This repository was archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
160 lines (135 loc) Β· 7.1 KB
/
index.js
File metadata and controls
160 lines (135 loc) Β· 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* https://www.pixiv.net/en/artworks/85933683
* Copyright (c) 2020 Cynthia K. Rey, Umut Δ°. ErdoΔan and other contributors
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
* 4. Each source code file must contain in it's header or footer a comment containing a
* hyperlink to a publicly accessible resource of an image of a "catgirl"
* (https://en.wikipedia.org/wiki/Catgirl).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const { Plugin } = require('powercord/entities');
const { Flex } = require('powercord/components');
const { findInReactTree } = require('powercord/util');
const { inject, uninject } = require('powercord/injector');
const { getModule, getModuleByDisplayName, React } = require('powercord/webpack');
const Settings = require('./settings');
const Cake = require('./cake');
module.exports = class CakeDay extends Plugin {
async startPlugin() {
this.loadStylesheet('style.scss');
powercord.api.settings.registerSettings(this.entityID, { category: this.entityID, label: 'Cake Day', render: Settings });
this.injectDM()
this.injectChat()
this.injectUserModal()
this.injectMemberList()
}
async pluginWillUnload() {
powercord.api.settings.unregisterSettings(this.entityID);
uninject('cake-day-dms');
uninject('cake-day-chat');
uninject('cake-day-members');
uninject('cake-day-user-profile-modals');
}
async injectDM() {
// DM Injection
const _this = this;
const users = await getModule(['getUsers']);
const PrivateChannel = await getModuleByDisplayName('PrivateChannel');
inject('cake-day-dms', PrivateChannel.prototype, 'render', function (_, res) {
if (!_this.settings.get('debug', false) && (!_this.settings.get('dms', true) || (users.getUser(this.props.user?.id)?.createdAt.getMonth() !== new Date().getMonth() || users.getUser(this.props.user?.id)?.createdAt.getDate() !== new Date().getDate()))) {
return res;
}
_this.log("Someone has a Cake Day! π");
// TODO: Idk if this will work with badges everywhere. Should check.
res.props.name = React.createElement('div', { className: 'cake-day-dm-wrapper' }, [
React.createElement('div', null, res.props.name),
React.createElement(Cake)
]);
return res;
});
}
async injectChat() {
// Chat Injection
const users = await getModule(['getUsers']);
const MessageHeader = await getModule(['MessageTimestamp']);
inject('cake-day-chat', MessageHeader, 'default', ([ { message: { author: { discriminator, id: userId }, } } ], res) => {
if (!this.settings.get('debug', false) && (!users.getUser(userId) || !this.settings.get('messages', true) || discriminator === "0000" || (users.getUser(userId)?.createdAt.getMonth() !== new Date().getMonth() || users.getUser(userId)?.createdAt.getDate() !== new Date().getDate()))) {
return res;
}
this.log("Someone has a Cake Day! π");
const header = findInReactTree(res, e => Array.isArray(e?.props?.children) && e.props.children.find(c => c?.props?.message));
header.props.children.push(React.createElement(Cake));
return res;
});
}
async injectMemberList() {
// Members List Injection
const _this = this;
const users = await getModule(['getUsers']);
const MemberListItem = await getModuleByDisplayName('MemberListItem');
inject('cake-day-members', MemberListItem.prototype, 'render', function (_, res) {
if (!_this.settings.get('debug', false) && (!_this.settings.get('membersList', true) || (users.getUser(this.props.user?.id)?.createdAt.getMonth() !== new Date().getMonth() || users.getUser(this.props.user?.id)?.createdAt.getDate() !== new Date().getDate()))) {
return res;
}
_this.log("Someone has a Cake Day! π");
res.props.decorators.props.children.push(React.createElement(Cake));
return res;
});
}
async injectUserModal() {
// User Modal Injection
const _this = this;
const users = await getModule(['getUsers']);
const UserProfileBody = await getUserProfileBody();
const { profileBadges } = await getModule([ 'profileBadges' ]);
inject('cake-day-user-profile-modals', UserProfileBody.prototype, 'renderBadges', function (_, res) {
const renderer = res.type;
res.type = (props) => {
const res = renderer(props);
if (!res) {
// There's no container if the user have no flags
return React.createElement(Flex, {
className: profileBadges,
basis: 'auto',
grow: 1,
shrink: 1
}, []);
}
if (_this.settings.get('debug', false) || (_this.settings.get('userProfileModals', true) && (users.getUser(this.props.user?.id)?.createdAt.getMonth() === new Date().getMonth() && users.getUser(this.props.user?.id)?.createdAt.getDate() === new Date().getDate()))) {
_this.log("Someone has a Cake Day! π");
res.props.children.push(React.createElement(Cake, { key: 'discord-cake-yaaay', clazz: 'cake-day-user-profile-modal' }));
}
return res;
};
return res;
});
}
}
async function getUserProfileBody () {
const UserProfile = await getModuleByDisplayName('UserProfile');
const VeryVeryDecoratedUserProfileBody = UserProfile.prototype.render().type;
const VeryDecoratedUserProfileBody = VeryVeryDecoratedUserProfileBody.prototype.render.call({ memoizedGetStateFromStores: () => void 0 }).type;
const DecoratedUserProfileBody = VeryDecoratedUserProfileBody.render().type;
return DecoratedUserProfileBody.prototype.render.call({ props: { forwardedRef: null } }).type;
}