/
HideDisabledEmojis.plugin.js
187 lines (174 loc) · 8.76 KB
/
HideDisabledEmojis.plugin.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* @name HideDisabledEmojis
* @description Hides disabled emojis from the emoji picker.
* @version 0.0.9
* @author Zerebos
* @authorId 249746236008169473
* @website https://github.com/rauenzi/BetterDiscordAddons/tree/master/Plugins/HideDisabledEmojis
* @source https://github.com/rauenzi/BetterDiscordAddons/blob/master/Plugins/HideDisabledEmojis/HideDisabledEmojis.plugin.js
*/
/*@cc_on
@if (@_jscript)
// Offer to self-install for clueless users that try to run this directly.
var shell = WScript.CreateObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\\BetterDiscord\\plugins");
var pathSelf = WScript.ScriptFullName;
// Put the user at ease by addressing them in the first person
shell.Popup("It looks like you've mistakenly tried to run me directly. \n(Don't do that!)", 0, "I'm a plugin for BetterDiscord", 0x30);
if (fs.GetParentFolderName(pathSelf) === fs.GetAbsolutePathName(pathPlugins)) {
shell.Popup("I'm in the correct folder already.", 0, "I'm already installed", 0x40);
} else if (!fs.FolderExists(pathPlugins)) {
shell.Popup("I can't find the BetterDiscord plugins folder.\nAre you sure it's even installed?", 0, "Can't install myself", 0x10);
} else if (shell.Popup("Should I copy myself to BetterDiscord's plugins folder for you?", 0, "Do you need some help?", 0x34) === 6) {
fs.CopyFile(pathSelf, fs.BuildPath(pathPlugins, fs.GetFileName(pathSelf)), true);
// Show the user where to put plugins in the future
shell.Exec("explorer " + pathPlugins);
shell.Popup("I'm installed!", 0, "Successfully installed", 0x40);
}
WScript.Quit();
@else@*/
const config = {
info: {
name: "HideDisabledEmojis",
authors: [
{
name: "Zerebos",
discord_id: "249746236008169473",
github_username: "rauenzi",
twitter_username: "ZackRauen"
}
],
version: "0.0.9",
description: "Hides disabled emojis from the emoji picker.",
github: "https://github.com/rauenzi/BetterDiscordAddons/tree/master/Plugins/HideDisabledEmojis",
github_raw: "https://github.com/rauenzi/BetterDiscordAddons/blob/master/Plugins/HideDisabledEmojis/HideDisabledEmojis.plugin.js"
},
changelog: [
{
title: "Bugs Squashed",
type: "fixed",
items: [
"Hides emojis in normal picker once again!",
"Hides emojis in the status emoji picker.",
"Hides extra unrelated buttons in status emoji picker."
]
}
],
main: "index.js"
};
class Dummy {
constructor() {this._config = config;}
start() {}
stop() {}
}
if (!global.ZeresPluginLibrary) {
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.name ?? config.info.name} is missing. Please click Download Now to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get("https://betterdiscord.app/gh-redirect?id=9", async (err, resp, body) => {
if (err) return require("electron").shell.openExternal("https://betterdiscord.app/Download?id=9");
if (resp.statusCode === 302) {
require("request").get(resp.headers.location, async (error, response, content) => {
if (error) return require("electron").shell.openExternal("https://betterdiscord.app/Download?id=9");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), content, r));
});
}
else {
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
}
});
}
});
}
module.exports = !global.ZeresPluginLibrary ? Dummy : (([Plugin, Api]) => {
const plugin = (Plugin, Api) => {
const {Patcher, DiscordModules, WebpackModules, Utilities} = Api;
return class HideDisabledEmojis extends Plugin {
async onStart() {
Patcher.after(DiscordModules.EmojiInfo, "isEmojiFiltered", (thisObject, methodArguments, returnValue) => {
return returnValue || DiscordModules.EmojiInfo.isEmojiDisabled(methodArguments[0], methodArguments[1]);
});
// BdApi.Webpack.Filters.byStrings("topEmojis", "getDisambiguatedEmojiContext")
let key = "";
const categoryMemo = WebpackModules.getModule(m => {
if (typeof(m) !== "object") return false;
const keys = Object.keys(m);
if (!keys.length) return false;
for (let k = 0; k < keys.length; k++) {
const val = m[keys[k]];
if (typeof(val?.toString) !== "function") continue;
const first = val.toString().includes("topEmojis");
const second = val.toString().includes("getDisambiguatedEmojiContext");
if (first && second) {
key = keys[k];
return true;
}
}
return false;
});
if (key && categoryMemo) {
Patcher.before(categoryMemo, key, (_, args) => {
// arg 0 = picker intention
// arg 1 = channel object
// arg 2 = guild id
// Create a fake channel object with a null guild id
// This fake object forces the categories to check isEmojiFiltered
if (args[1] == null) {
args[1] = {
getGuildId: () => null
};
}
});
}
const doFiltering = props => {
props.rowCountBySection = props.rowCountBySection.filter((c, i) => c || props.collapsedSections.has(props.sectionDescriptors[i].sectionId));
props.sectionDescriptors = props.sectionDescriptors.filter(s => s.count || props.collapsedSections.has(s.sectionId));
const wasFiltered = props.emojiGrid.filtered;
props.emojiGrid = props.emojiGrid.filter(r => r.length);
if (wasFiltered) props.emojiGrid.filtered = true; // Reassign
};
const PickerWrapMemo = WebpackModules.getModule(m => m?.type?.render?.toString?.()?.includes("EMOJI_PICKER_POPOUT"));
Patcher.after(PickerWrapMemo.type, "render", (_, [inputProps], ret) => {
const pickerChild = Utilities.findInTree(ret, m => m?.props?.emojiGrid, {walkable: ["props", "children"]});
if (!pickerChild?.type?.type) return;
ret.props.children.props.page = "DM Channel";
if (pickerChild.type.type.__patched) return;
Patcher.before(pickerChild.type, "type", (_, [props]) => {
if (!props.rowCountBySection) return;
if (props.emojiGrid.filtered) return doFiltering(props);
props.emojiGrid.filtered = true;
let row = 0;
for (let s = 0; s < props.sectionDescriptors.length; s++) {
const section = props.sectionDescriptors[s];
const rowCount = props.rowCountBySection[s];
const rowEnd = row + rowCount - 1;
let countLeft = 0;
let rowsLeft = 0;
for (let r = row; r <= rowEnd; r++) {
// If it's not disabled or if it's the upload button in status picker
props.emojiGrid[r] = props.emojiGrid[r].filter(e => !e.isDisabled && (e.type !== 1 || inputProps?.pickerIntention !== 1));
const remaining = props.emojiGrid[r].length;
if (remaining) {
rowsLeft = rowsLeft + 1;
countLeft = countLeft + remaining;
}
}
section.count = countLeft;
props.rowCountBySection[s] = rowsLeft;
row = rowEnd + 1;
}
doFiltering(props);
});
pickerChild.type.type.__patched = true;
});
}
onStop() {
Patcher.unpatchAll();
}
};
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
/*@end@*/