forked from JustOptimize/ShowHiddenChannels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowHiddenChannels.plugin.js
439 lines (381 loc) · 15.4 KB
/
ShowHiddenChannels.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/**
* @name ShowHiddenChannels
* @displayName Show Hidden Channels (SHC)
* @version 0.0.5
* @author JustOptimize (Oggetto)
* @authorId 347419615007080453
* @source https://github.com/JustOptimize/return-ShowHiddenChannels
* @updateUrl https://raw.githubusercontent.com/JustOptimize/return-ShowHiddenChannels/main/ShowHiddenChannels.plugin.js
*/
module.exports = (() => {
const config = {
info: {
name: "ShowHiddenChannels",
authors: [{
name: "JustOptimize (Oggetto)",
}],
description: "A plugin which displays all hidden Channels, which can't be accessed due to Role Restrictions, this won't allow you to read them (impossible).",
version: "0.0.5",
github: "https://github.com/JustOptimize/return-ShowHiddenChannels",
github_raw: "https://raw.githubusercontent.com/JustOptimize/return-ShowHiddenChannels/main/ShowHiddenChannels.plugin.js"
},
changelog: [
{
title: "v0.0.5",
items: [
"Added more settings for the lock icon.",
]
},
{
title: "v0.0.4",
items: [
"Added some settings to the plugin.",
]
},
{
title: "v0.0.3",
items: [
"Added lock icon to hidden channels",
],
}
],
defaultConfig: [
{
type: "switch",
id: "disableIcons",
name: "Disable lock icons",
note: "This setting disables the hidden channel icons (they will be seen as normal channels).",
value: false
},
{
type: "textbox",
id: "emoji",
name: "Locked Channel Emoji/Text",
note: "The emoji/text to use for the lock icon (MAX 6).",
value: "🔒"
},
{
type: "switch",
id: "OnRight",
name: "Emoji/Text on the right",
note: "This setting changes the position of the lock icon to the left or right side of the channel name.",
value: false
},
{
type: "switch",
id: "debugMode",
name: "Enable Debug Mode",
note: "Enables some functions that are used for the development of the plugin.",
value: false
},
],
main: "ShowHiddenChannels.plugin.js",
};
return !window.hasOwnProperty("ZeresPluginLibrary")
? class {
load() {
BdApi.showConfirmationModal(
"ZLib Missing",
`The library plugin (ZeresPluginLibrary) needed for ${config.info.name} is missing. Please click Download Now to install it.`,
{
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => this.downloadZLib(),
}
);
}
async downloadZLib() {
const fs = require("fs");
const path = require("path");
const ZLib = await fetch("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js");
if (!ZLib.ok) return this.errorDownloadZLib();
const ZLibContent = await ZLib.text();
try {
await fs.writeFile(
path.join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"),
ZLibContent,
(err) => {
if (err) return this.errorDownloadZLib();
}
);
} catch (err) {
return this.errorDownloadZLib();
}
}
errorDownloadZLib() {
const { shell } = require("electron");
BdApi.showConfirmationModal(
"Error Downloading",
[
`ZeresPluginLibrary download failed. Manually install plugin library from the link below.`,
],
{
confirmText: "Download",
cancelText: "Cancel",
onConfirm: () => {
shell.openExternal(
"https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js"
);
},
}
);
}
start() {}
stop() {}
}
: (([Plugin, Library]) => {
const {
Patcher,
WebpackModules,
PluginUpdater,
Logger,
Modals,
// Utilities,
DiscordModules: {
MessageActions,
// React,
// Tooltip,
// Clickable
}
} = Library;
const ChannelStore = WebpackModules.getByProps("getChannel");
const Channel = WebpackModules.getByPrototypes("isManaged");
const DiscordConstants = WebpackModules.getModule((m) => m?.Plq?.ADMINISTRATOR == 8n);
const ChannelPermissionStore = WebpackModules.getByProps("getChannelPermissions");
const UnreadStore = WebpackModules.getByProps("isForumPostUnread");
// const ChannelItem = WebpackModules.getByString("canHaveDot", "unreadRelevant", "UNREAD_HIGHLIGHT")
// const ChannelClasses = WebpackModules.getByProps("wrapper", "mainContent");
// const { iconItem, iconBase, actionIcon } = WebpackModules.getByProps("iconItem"); //iconItem-1EjiK0 iconBase-2G48Fc actionIcon-2sw4Sl
// const registry = WebpackModules.getModules((m) => typeof m === "function" && m.toString().indexOf('"currentColor"') !== -1);
//TODO: Icon not working
// const Icon = (props) => {
// // const mdl = registry.find((m) => m.displayName === props.name);
// const Icon = "link?"; //! link
// const newProps = global._.cloneDeep(props);
// delete newProps.name;
// return React.createElement(Icon, newProps);
// };
// console.log(registry);
// Icon.Names = registry.map((m) => m.name); //! displayName got removed so need to find unique identifier for the icon
// console.log(Icon.Names)
// //TODO, Coming soon
// const Route = WebpackModules.getModule((m) => m?.default?.toString().includes("impression"));
// const ChannelUtil = WebpackModules.getByProps("selectChannel", "selectPrivateChannel");
// const VoiceUser = WebpackModules.getByPrototypes("renderPrioritySpeaker", "renderIcons", "renderAvatar")
// const VoiceUsers = WebpackModules.getByString("hidePreview", "previewIsOpen", "previewUserIdAfterDelay");
// const ChannelContextMenu = WebpackModules.getByProps("openContextMenu");
return class ShowHiddenChannels extends Plugin {
constructor() {
super();
this.can = ChannelPermissionStore.can.__originalFunction ?? ChannelPermissionStore.can;
const _this = this;
if (!Channel.prototype.isHidden)
Channel.prototype.isHidden = function () {
return (![1, 3].includes(this.type) && !_this.can(DiscordConstants.Plq.VIEW_CHANNEL, this)
);
};
}
checkForUpdates() {
try {
PluginUpdater.checkForUpdate(
config.info.name,
config.info.version,
config.info.github_raw
);
} catch (err) {
Logger.err("Plugin Updater could not be reached.", err);
}
}
onStart() {
this.checkForUpdates();
this.Patch();
}
Patch() {
if(this.settings.debugMode) {
console.log("UnreadStore", UnreadStore);
console.log("ChannelStore", ChannelStore);
}
//* List of UnreadStore functions:
// - getMentionCount
// - getUnreadCount
// - hasNotableUnread
// - hasRelevantUnread
// - hasUnread
Patcher.after(UnreadStore, "getMentionCount", (_, args, res) => {
return ChannelStore.getChannel(args[0])?.isHidden() ? 0 : res;
});
Patcher.after(UnreadStore, "getUnreadCount", (_, args, res) => {
return ChannelStore.getChannel(args[0])?.isHidden() ? 0 : res;
});
//! Seems like this is not working anymore
// Patcher.after(UnreadStore, "hasAnyUnread", (_, args, res) => {
// console.log("hasAnyUnread", args, res);
// return res && !ChannelStore.getChannel(args[0])?.isHidden();
// });
Patcher.after(UnreadStore, "hasNotableUnread", (_, args, res) => {
return res && !ChannelStore.getChannel(args[0])?.isHidden();
});
Patcher.after(UnreadStore, "hasRelevantUnread", (_, args, res) => {
return res && !args[0].isHidden();
});
Patcher.after(UnreadStore, "hasUnread", (_, args, res) => {
return res && !ChannelStore.getChannel(args[0])?.isHidden();
});
//* Make hidden channel visible
Patcher.after(ChannelPermissionStore, "can", (_, args, res) => {
if (args[0] == DiscordConstants.Plq.VIEW_CHANNEL) {
return true;
}
if (args[1]?.isHidden?.() && args[0] == DiscordConstants.Plq.CONNECT)
return false;
return res;
});
//* Stop fetching messages if the channel is hidden
//Route.default.displayName = "RouteWithImpression"; //! No displayName so i don't know what to replace
if (!MessageActions._fetchMessages) {
MessageActions._fetchMessages = MessageActions.fetchMessages;
MessageActions.fetchMessages = (args) => {
if (ChannelStore.getChannel(args.channelId)?.isHidden?.()){
BdApi.showToast("Channel is hidden, not fetching messages", {type: "error"});
return;
}
return MessageActions._fetchMessages(args);
};
}
if (!this.settings.disableIcons){ // && !this.settings.useOgIcons
var channelChanging = false; // Thanks to vileelf for suggesting a fix for this
var icon = this.settings.emoji || "🔒";
Patcher.after(ChannelStore, "getChannel", (thisObject, methodArguments, returnValue) => {
if (channelChanging) { return returnValue; }
channelChanging = true;
if (returnValue?.isHidden?.() && returnValue?.name && !returnValue.name.includes(" " + icon + " ")) {
if(this.settings.OnRight) {
returnValue.name = returnValue.name + " " + icon + " ";
} else {
returnValue.name = " " + icon + " " + returnValue.name;
}
}
channelChanging = false;
});
}
//! Not working
// if (this.settings.useOgIcons && !this.settings.disableIcons) {
// console.log("ChannelItem", ChannelItem);
// Patcher.after(ChannelItem, "default", (_, args, res) => {
// console.log(args[0].channel);
// const instance = args[0];
// if (instance.channel?.isHidden()) {
// const item = res.props?.children?.props;
// if (item?.className) item.className += ` shc-hidden-channel shc-hidden-channel-type-${instance.channel.type}`;
// const children = res.props?.children?.props?.children[1]?.props?.children[1];
// if (children.props?.children) {
// children.props.children = [
// React.createElement(Tooltip, {
// text: "Hidden Channel",
// },
// React.createElement(Clickable,
// {
// className: [iconItem, "shc-lock-icon-clickable"].join(
// " "
// ),
// style: {
// display: "block",
// },
// },
// // React.createElement(Icon, {
// // // Icon, {
// // // name: "Eye", //! no name for stuff so i don't know
// // // className: actionIcon,
// // className: [iconBase, actionIcon].join(" "),
// // style: {
// // color: "red",
// // width: "20px",
// // height: "20px",
// // },
// // })
// React.createElement('svg', Clickable, children, React.createElement('path', {
// style: {
// width: "24",
// height: "24",
// class: "shc-lock-icon",
// viewBox: "0 0 24 24",
// // aria-hidden: "true",
// role: "img",
// },
// d: 'M6 6h1v6H6zm3 0h1v6H9z'
// }), React.createElement('path', {
// style: {
// fill: "currentColor",
// },
// d: 'M17 11V7C17 4.243 14.756 2 12 2C9.242 2 7 4.243 7 7V11C5.897 11 5 11.896 5 13V20C5 21.103 5.897 22 7 22H17C18.103 22 19 21.103 19 20V13C19 11.896 18.103 11 17 11ZM12 18C11.172 18 10.5 17.328 10.5 16.5C10.5 15.672 11.172 15 12 15C12.828 15 13.5 15.672 13.5 16.5C13.5 17.328 12.828 18 12 18ZM15 11H9V7C9 5.346 10.346 4 12 4C13.654 4 15 5.346 15 7V11Z'
// }))
// )
// ),
// ];
// }
// if (instance.channel.type == DiscordConstants.ChannelTypes.GUILD_VOICE && !instance.connected) {
// const wrapper = Utilities.findInReactTree(res, (n) => n?.props?.className?.includes(ChannelClasses.wrapper));
// if (wrapper) {
// wrapper.props.onMouseDown = () => {};
// wrapper.props.onMouseUp = () => {};
// }
// const mainContent = Utilities.findInReactTree(res, (n) =>
// n?.props?.className?.includes(ChannelClasses.mainContent)
// );
// if (mainContent) {
// mainContent.props.onClick = () => {};
// mainContent.props.href = null;
// }
// }
// }
// return res;
// });
//! Not working, will be fixed in the future (maybe, idk if i should)
// ChannelItem.default.displayName = "ChannelItem"; //! No displayName so i don't know what to replace
// Patcher.before(ChannelUtil, "getChannelIconComponent", (_, args) => {
// if (args[0]?.isHidden?.() && args[2]?.locked)
// args[2].locked = false;
// return args;
// }
// );
//! Tried this, not working too
// Patcher.after(ChannelContextMenu, "default", (_, args, res) => {
// console.log(args[0].channel);
// const instance = args[0];
// if (instance.channel?.isHidden?.()) {
// console.log("hidden");
// }
// });
}
onStop() {
Patcher.unpatchAll();
}
//* Settings
getSettingsPanel() {
const panel = this.buildSettingsPanel();
panel.addListener(this.updateSettings.bind(this));
return panel.getElement();
}
updateSettings(id, value) {
if(id === "emoji") {
if(value.length > 6) { value = value.substring(0, 6); }
else if(value.length < 1) { value = "🔒"; }
this.settings.emoji = value;
this.saveSettings(this.settings);
return;
}
this.reloadNotification();
}
//* Icon
reloadNotification(coolText = "Reload Discord to apply changes and avoid bugs") {
Modals.showConfirmationModal("Reload Discord?", coolText, {
confirmText: "Reload",
cancelText: "Later",
onConfirm: () => {
window.location.reload();
}
});
}
};
})(global.ZeresPluginLibrary.buildPlugin(config));
})();