This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
167 lines (131 loc) · 5.09 KB
/
index.js
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
161
162
163
164
165
166
167
const { Plugin } = require('powercord/entities');
const { join } = require('path');
const { React, getModule, getAllModules } = require('powercord/webpack');
const { forceUpdateElement, getOwnerInstance } = require('powercord/util');
const { inject, uninject } = require('powercord/injector');
const { get } = require('powercord/http');
const { loadStyle, unloadStyle } = require('./util');
const Badges = require('./Badges');
const cache = { _guilds: {} };
const REFRESH_INTERVAL = 1000 * 60 * 30;
module.exports = class GlobalBadges extends Plugin {
startPlugin() {
this.injectUsers();
this.loadStylesheet(join(__dirname, 'style.css'));
};
pluginWillUnload () {
uninject('gb-badges-users')
uninject('gb-badges-users-render');
uninject('gb-badges-users-update');
uninject('gb-badges-users-fetch');
const containerClasses = getModule([ 'subscribeTooltipText' ], false);
const modalClasses = getModule([ 'topSectionNormal' ], false);
if (containerClasses) {
forceUpdateElement(`.${containerClasses.container}`);
}
if (modalClasses) {
const modalHeader = document.querySelector(`.${modalClasses.topSectionNormal} header`);
if (modalHeader) {
const instance = getOwnerInstance(modalHeader);
(instance._reactInternals || instance._reactInternalFiber).return.stateNode.forceUpdate();
}
}
}
async injectUsers () {
const UserProfileBadgeList = getAllModules((m) => m.default?.displayName === 'UserProfileBadgeList')[1]; // Discord have two identical components but only 2nd is actually used?
inject('gb-badges-users', UserProfileBadgeList, 'default', ([ props ], res) => {
const [ badges, setBadges ] = React.useState(null);
const userId = props.user.id;
React.useEffect(async () => {
if (!cache[userId] || cache[userId].lastFetch < Date.now() - REFRESH_INTERVAL) {
cache[userId] = await get(`https://api.obamabot.me/v2/text/badges?user=${userId}`)
.catch((e) => e)
.then((res) => {
if (res.statusCode === 200 || res.statusCode === 404) {
return{
badges: res.body || {},
lastFetch: Date.now()
};
}
delete cache[userId];
return {
badges: {},
lastFetch: Date.now()
};
});
}
setBadges(cache[userId].badges);
}, []);
if (!badges) {
return res;
}
const render = (Component, key, props = {}) => (
React.createElement(Component, {
key: `gb-${key}`,
...props
})
);
if (badges.BDB && badges.BDB.name && badges.BDB.img) {
res.props.children.push(render(Badges.BDB, 'bdb', badges.BDB));
}
// Aliucord
// Aliucord Contributor
if (badges.aliu.roles && badges.aliu.roles.find(r => r == 'contributor')) {
res.props.children.push(render(Badges.aliucordContr, 'aliucordContributor'));
}
// Aliucord Donor
if (badges.aliu.roles && badges.aliu.roles.find(r => r == 'donor')) {
res.props.children.push(render(Badges.aliucordDono, 'aliucordDonor'));
}
// Aliucord Staff
if (badges.aliu.roles && badges.aliu.roles.find(r => r == 'dev')) {
res.props.children.push(render(Badges.aliucordDev, 'aliucordDev'));
}
// Aliucord Custom Badge
if (badges.aliu.roles && badges.aliu.custom) {
res.props.children.push(render(Badges.aliucordCustom, 'aliucordCustom', badges.aliu.custom[0]));
}
// Better Discord
// BD Devs
if (badges.BD) {
res.props.children.push(render(Badges.BDDevs, 'BDDevs'));
}
// Enmity
// EN Devs
if (badges.enmity && badges.enmity.dev) {
res.props.children.push(render(Badges.EnDevs, 'ENDevs', badges.enmity.dev.data));
}
// EN Contributors
if (badges.enmity && badges.enmity.contributor) {
res.props.children.push(render(Badges.EnDevs, 'ENContributor', badges.enmity.contributor.data));
}
// EN Staff
if (badges.enmity && badges.enmity.staff) {
res.props.children.push(render(Badges.EnStaff, 'ENStaff', badges.enmity.staff.data));
}
// EN supporter
if (badges.enmity && badges.enmity.supporter) {
res.props.children.push(render(Badges.EnSupporter, 'ENSupporter', badges.enmity.supporter.data));
}
// EN Custom
if (badges.enmity && badges.enmity[userId]) {
res.props.children.push(render(Badges.EnCustom, 'EnCustom', badges.enmity[userId].data));
}
// Goosemode
// GM Sponsor
if (badges.goosemod && badges.goosemod.sponsor) {
res.props.children.push(render(Badges.GMSponsor, 'GMSponsor'));
}
// GM Sponsor
if (badges.goosemod && badges.goosemod.dev) {
res.props.children.push(render(Badges.GMTranslator, 'GMTranslator'));
}
// GM Sponsor
if (badges.goosemod && badges.goosemod.translator) {
res.props.children.push(render(Badges.GMDeveloper, 'GMDeveloper'));
}
return res;
});
UserProfileBadgeList.default.displayName = 'UserProfileBadgeList';
}
}