This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 334
/
FakeDeafen.plugin.js
609 lines (608 loc) · 20.7 KB
/
FakeDeafen.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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
/**
* @name FakeDeafen
* @author Ahlawat
* @authorId 1025214794766221384
* @version 1.4.4
* @invite SgKSKyh9gY
* @description Fake your audio status, to make it look like you are muted or deafened when you're not.
* @website https://tharki-god.github.io/
* @source https://github.com/Tharki-God/BetterDiscordPlugins
* @updateUrl https://tharki-god.github.io/BetterDiscordPlugins/FakeDeafen.plugin.js
*/
/*@cc_on
@if (@_jscript)
var shell = WScript.CreateObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\\BetterDiscord\\plugins");
var pathSelf = WScript.ScriptFullName;
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 move myself to BetterDiscord's plugins folder for you?", 0, "Do you need some help?", 0x34) === 6) {
fs.MoveFile(pathSelf, fs.BuildPath(pathPlugins, fs.GetFileName(pathSelf)));
shell.Exec("explorer " + pathPlugins);
shell.Popup("I'm installed!", 0, "Successfully installed", 0x40);
}
WScript.Quit();
@else@*/
module.exports = (() => {
const config = {
info: {
name: "FakeDeafen",
authors: [
{
name: "Ahlawat",
discord_id: "1025214794766221384",
github_username: "Tharki-God",
},
],
version: "1.4.4",
description:
"Fake your audio status, to make it look like you are muted or deafened when you're not.",
github: "https://github.com/Tharki-God/BetterDiscordPlugins",
github_raw:
"https://tharki-god.github.io/BetterDiscordPlugins/FakeDeafen.plugin.js",
},
changelog: [
{
title: "v0.2.3",
items: ["Easier To use Now"],
},
{
title: "v0.2.4",
items: ["Reindented file"],
},
{
title: "v0.2.6",
items: ["Fixed some bugs, and made the code better looking."],
},
{
title: "v0.3.7",
items: ["Updater Library, Meta Update url having bugs."],
},
{
title: "v0.3.8",
items: ["Wifey.exe executed, lol ヾ(•ω•`)o."],
},
{
title: "v0.3.9",
items: ["Refractor"],
},
{
title: "v0.4.0",
items: ["Library Handler"],
},
{
title: "Initial Release v1.0.0",
items: [
"This is the initial release of the plugin :)",
"Fool them all (●'◡'●)",
],
},
{
title: "v1.0.2",
items: ["Added Fake Video", "Removed Useless code"],
},
{
title: "v1.0.6",
items: ["Option to toogle without disabling plugin itself."],
},
{
title: "v1.0.9",
items: ["Keybind to toogle, by default: CTRL+D."],
},
{
title: "v1.3.2",
items: ["Corrected text."],
},
],
main: "FakeDeafen.plugin.js",
};
const RequiredLibs = [{
window: "ZeresPluginLibrary",
filename: "0PluginLibrary.plugin.js",
external: "https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js",
downloadUrl: "https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js"
},
{
window: "BunnyLib",
filename: "1BunnyLib.plugin.js",
external: "https://github.com/Tharki-God/BetterDiscordPlugins",
downloadUrl: "https://tharki-god.github.io/BetterDiscordPlugins/1BunnyLib.plugin.js"
},
];
class handleMissingLibrarys {
load() {
for (const Lib of RequiredLibs.filter(lib => !window.hasOwnProperty(lib.window)))
BdApi.showConfirmationModal(
"Library Missing",
`The library plugin (${Lib.window}) needed for ${config.info.name} is missing. Please click Download Now to install it.`,
{
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => this.downloadLib(Lib),
}
);
}
async downloadLib(Lib) {
const fs = require("fs");
const path = require("path");
const { Plugins } = BdApi;
const LibFetch = await fetch(
Lib.downloadUrl
);
if (!LibFetch.ok) return this.errorDownloadLib(Lib);
const LibContent = await LibFetch.text();
try {
await fs.writeFile(
path.join(Plugins.folder, Lib.filename),
LibContent,
(err) => {
if (err) return this.errorDownloadLib(Lib);
}
);
} catch (err) {
return this.errorDownloadLib(Lib);
}
}
errorDownloadZLib(Lib) {
const { shell } = require("electron");
BdApi.showConfirmationModal(
"Error Downloading",
[
`${Lib.window} download failed. Manually install plugin library from the link below.`,
],
{
confirmText: "Download",
cancelText: "Cancel",
onConfirm: () => {
shell.openExternal(
Lib.external
);
},
}
);
}
start() { }
stop() { }
}
return RequiredLibs.some(m => !window.hasOwnProperty(m.window))
? handleMissingLibrarys
: (([Plugin, ZLibrary]) => {
const {
WebpackModules,
Toasts,
Utilities,
PluginUpdater,
Logger,
DOMTools,
Settings: { SettingPanel, SettingGroup, Switch },
DiscordModules: { React, LocaleManager },
} = ZLibrary;
const { Patcher, ContextMenu } = BdApi;
const {
LibraryUtils,
ReactUtils,
LibraryIcons,
Settings: { Keybind },
LibraryModules: {
WindowInfoStore,
KeybindUtils,
AccountDetails,
PanelButton,
Menu,
StatusPicker,
SoundModule,
NotificationStore,
AudioUtils,
GatewayConnectionStore
}
} = BunnyLib.build(config);
const NotificationVars = () => NotificationStore.__getLocalVars();
const CSS = `.withTagAsButton-OsgQ9L {
min-width:0;
}
`;
const Sounds = {
Enable: "reconnect",
Disable: "stream_ended",
};
const defaultSettings = {
toFake: {
mute: true,
deaf: true,
video: false,
},
statusPicker: true,
userPanel: false,
playAudio: false,
showToast: true,
keybind: KeybindUtils.Kd("ctrl+d"),
};
return class FakeDeafen extends Plugin {
constructor() {
super();
this.currentlyPressed = {};
this.keybindListener = this.keybindListener.bind(this);
this.cleanCallback = this.cleanCallback.bind(this);
this.settings = Utilities.loadData(
config.info.name,
"settings",
defaultSettings
);
this.enabled = Utilities.loadData(
config.info.name,
"enabled",
true
);
}
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.init();
this.addListeners();
}
addListeners() {
window.addEventListener("keydown", this.keybindListener);
window.addEventListener("keyup", this.keybindListener);
WindowInfoStore.addChangeListener(this.cleanCallback);
}
async init() {
if (this.enabled) await this.fakeIt();
if (this.settings["statusPicker"]) this.patchStatusPicker();
if (this.settings["userPanel"]) this.patchPanelButton();
}
patchStatusPicker() {
Patcher.before(config.info.name, Menu, "ZP", (_, args) => {
if (args[0]?.navId != "account") return args;
const [
{
children
}
] = args;
const Icon = ReactUtils.addStyle(LibraryIcons.Sound("16", "16"), {
marginLeft: "-2px",
});
const DisabledIcon = ReactUtils.addChilds(Icon, React.createElement("polygon", {
style: {
fill: "#a61616",
},
points:
"22.6,2.7 22.6,2.8 19.3,6.1 16,9.3 16,9.4 15,10.4 15,10.4 10.3,15 2.8,22.5 1.4,21.1 21.2,1.3 ",
}));
const switchAccount = children.find(
(c) => c?.props?.children?.key == "switch-account"
);
if (!children.find((c) => c?.props?.className == "tharki"))
children.splice(
children.indexOf(switchAccount),
0,
React.createElement(Menu.kS, {
className: "tharki",
children: [],
})
);
const section = children.find(
(c) => c?.props?.className == "tharki"
);
if (
!section.props.children.find((m) => m?.props?.id == "fake-deafen")
)
section.props.children.push(
React.createElement(Menu.sN, {
id: "fake-deafen",
keepItemStyles: true,
action: () => {
return this.toggle();
},
render: () =>
React.createElement(
"div",
{
onContextMenu: (event) =>
this.renderContextMenu(event),
className: StatusPicker.statusItem,
"aria-label": `${this.enabled ? "Unfake" : "Fake"
} audio status`,
},
this.enabled ? Icon : DisabledIcon,
React.createElement(
"div",
{
className: StatusPicker.status,
},
`${this.enabled ? "Unfake" : "Fake"} audio status`
),
React.createElement(
"div",
{
className: StatusPicker.description,
},
`Whether to ${this.enabled ? "unfake" : "fake"
} deafen/mute/video status for others.`
)
),
})
);
});
}
patchPanelButton() {
DOMTools.addStyle(config.info.name, CSS);
Patcher.before(config.info.name, AccountDetails, "Z", (_, args) => {
const [{ children }] = args;
if (
!children?.some?.(
(m) =>
m?.props?.tooltipText == LocaleManager.Messages["MUTE"] ||
m?.props?.tooltipText == LocaleManager.Messages["UNMUTE"]
)
)
return;
const Icon = LibraryIcons.Sound("20", "20");
const DisabledIcon = ReactUtils.addChilds(Icon, React.createElement("polygon", {
style: {
fill: "#a61616",
},
points:
"22.6,2.7 22.6,2.8 19.3,6.1 16,9.3 16,9.4 15,10.4 15,10.4 10.3,15 2.8,22.5 1.4,21.1 21.2,1.3 ",
}));
children.unshift(
React.createElement(PanelButton, {
onContextMenu: (event) => this.renderContextMenu(event),
icon: () =>
this.enabled
? Icon
: DisabledIcon,
tooltipText: `${this.enabled ? "Unfake" : "Fake"
} audio status`,
onClick: () => {
this.toggle();
},
})
);
});
}
renderContextMenu(event) {
ContextMenu.open(
event,
ContextMenu.buildMenu([
{
label: "What to fake?",
type: "text",
},
{
type: "separator",
},
{
type: "toggle",
label: "Mute",
checked: this.settings["toFake"]["mute"],
action: () => {
this.settings["toFake"]["mute"] =
!this.settings["toFake"]["mute"];
this.saveSettings();
},
},
{
type: "toggle",
label: "Deafen",
checked: this.settings["toFake"]["deaf"],
action: () => {
this.settings["toFake"]["deaf"] =
!this.settings["toFake"]["deaf"];
this.saveSettings();
},
},
{
type: "toggle",
label: "Video",
checked: this.settings["toFake"]["video"],
action: () => {
this.settings["toFake"]["video"] =
!this.settings["toFake"]["video"];
this.saveSettings();
},
},
])
);
}
onStop() {
Patcher.unpatchAll("fake-deafen");
Patcher.unpatchAll(config.info.name);
this.removeListeners();
DOMTools.removeStyle(config.info.name);
}
removeListeners() {
window.removeEventListener("keydown", this.keybindListener);
window.removeEventListener("keyup", this.keybindListener);
WindowInfoStore.removeChangeListener(this.cleanCallback);
}
cleanCallback() {
if (WindowInfoStore.isFocused()) this.currentlyPressed = {};
}
keybindListener(e) {
const keybindEvent = KeybindUtils.d2(this.settings["keybind"]);
if (
e.type == "keyup" &&
keybindEvent.length &&
keybindEvent.every(
(ev) =>
Object.keys(ev)
.filter((k) => k !== "keyCode")
.every((k) => ev[k] == e[k]) &&
this.currentlyPressed[ev["keyCode"]]
)
) {
if (this.settings["showToast"])
Toasts.show(
`${this.enabled ? "Unfaked" : "Faked"} audio status`,
{
icon: "https://tharki-god.github.io/files-random-host/sound%20fake%20deaf.png",
timeout: 1000,
type: "success",
}
);
this.toggle();
}
this.currentlyPressed[e.keyCode] = e.type == "keydown";
}
toggle() {
if (this.settings["playAudio"])
SoundModule.GN(
this.enabled ? Sounds.Disable : Sounds.Enable,
0.5
);
this.enabled ? this.unfakeIt() : this.fakeIt();
}
unfakeIt() {
Patcher.unpatchAll("fake-deafen");
this.enabled = false;
Utilities.saveData(config.info.name, "enabled", this.enabled);
this.update();
}
async fakeIt() {
const voiceSocket = GatewayConnectionStore.getSocket();
Patcher.instead(
"fake-deafen",
voiceSocket,
"voiceStateUpdate",
(instance, args) => {
instance.send(4, {
guild_id: args[0].guildId,
channel_id: args[0].channelId,
preferredRegion: args[0].preferredRegion,
self_mute:
this.settings["toFake"]["mute"] || args[0].selfMute,
self_deaf:
this.settings["toFake"]["deaf"] || args[0].selfDeaf,
self_video:
this.settings["toFake"]["video"] || args[0].selfVideo,
});
}
);
this.enabled = true;
Utilities.saveData(config.info.name, "enabled", this.enabled);
this.update();
}
async update() {
const toCheck = ["mute", "unmute"];
const toToggle = toCheck.filter(
(sound) => !NotificationVars().state.disabledSounds.includes(sound)
);
if (toToggle.length > 0)
Object.defineProperty(NotificationVars().state, "disabledSounds", {
value: [...toToggle, ...NotificationVars().state.disabledSounds],
writable: true,
});
await AudioUtils.toggleSelfMute();
await LibraryUtils.Sleep(100);
AudioUtils.toggleSelfMute();
if (toToggle.length > 0)
Object.defineProperty(NotificationVars().state, "disabledSounds", {
value: NotificationVars().state.disabledSounds.filter(
(sound) => !toToggle.includes(sound)
),
writable: true,
});
}
getSettingsPanel() {
return SettingPanel.build(
this.saveSettings.bind(this),
new SettingGroup("What to fake?", {
collapsible: true,
shown: false,
}).append(
new Switch(
"Mute",
"Whether you want to fake mute or not.",
this.settings["toFake"]["mute"],
(e) => {
this.settings["toFake"]["mute"] = e;
}
),
new Switch(
"Deafen",
"Whether you want to fake deafen or not.",
this.settings["toFake"]["deaf"],
(e) => {
this.settings["toFake"]["deaf"] = e;
}
),
new Switch(
"Video",
"Whether you want to fake video or not.",
this.settings["toFake"]["video"],
(e) => {
this.settings["toFake"]["video"] = e;
}
)
),
new SettingGroup("Toggle options", {
collapsible: true,
shown: false,
}).append(
new Keybind(
"Toggle by keybind:",
"Keybind to toggle faking.",
this.settings["keybind"],
(e) => {
this.settings["keybind"] = e;
}
),
new Switch(
"Show toasts",
"Whether to show toasts on using keybinds.",
this.settings["showToast"],
(e) => {
this.settings["showToast"] = e;
}
),
new Switch(
"Status picker",
"Add an option in the status picker to toggle faking.",
this.settings["statusPicker"],
(e) => {
this.settings["statusPicker"] = e;
}
),
new Switch(
"User panel",
"Add a button in the user panel to toggle faking.",
this.settings["userPanel"],
(e) => {
this.settings["userPanel"] = e;
}
),
new Switch(
"Play audio",
"Play a sound upon using the keybind or clicking the button in the status picker or user panel.",
this.settings["playAudio"],
(e) => {
this.settings["playAudio"] = e;
}
)
)
);
}
saveSettings() {
Utilities.saveData(config.info.name, "settings", this.settings);
Patcher.unpatchAll("fake-deafen");
Patcher.unpatchAll(config.info.name);
this.init();
}
};
})(ZLibrary.buildPlugin(config));
})();
/*@end@*/