forked from Metalloriff/BetterDiscordPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NateUtilities.plugin.js
178 lines (124 loc) · 6.33 KB
/
NateUtilities.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
//META{"name":"NateUtilities"}*//
class NateUtilities {
getName() { return "NateUtilities"; }
getDescription() { return "For all of your ear and brain saving needs! If you don't know what this plugin is, it's not for you, just ignore it."; }
getVersion() { return "0.0.2"; }
getAuthor() { return "Metalloriff"; }
getChanges() {
return {
};
}
load() {}
start() {
let libLoadedEvent = () => {
try{ this.onLibLoaded(); }
catch(err) { console.error(this.getName(), "fatal error, plugin could not be started!", err); }
};
let lib = document.getElementById("NeatoBurritoLibrary");
if(lib == undefined) {
lib = document.createElement("script");
lib.setAttribute("id", "NeatoBurritoLibrary");
lib.setAttribute("type", "text/javascript");
lib.setAttribute("src", "https://rawgit.com/NeatoLib/BetterDiscordPlugins/master/Lib/NeatoBurritoLibrary.js");
document.head.appendChild(lib);
}
if(typeof window.NeatoLib !== "undefined") libLoadedEvent();
else lib.addEventListener("load", libLoadedEvent);
}
getSettingsPanel() {
setTimeout(() => {
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createKeybindInput("local mute nate", this.settings.muteHotkey, newKey => {
this.unregisterKeybinds();
if(newKey) {
this.settings.muteHotkey = newKey;
this.registerKeybinds();
this.saveSettings();
} else PluginUtilities.showToast("You did not input anything!", { type : "error" });
}, { description : "For when your ears and/or brain need a break.", global : true }), this.getName());
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createKeybindInput("server mute nate", this.settings.serverMuteHotkey, newKey => {
this.unregisterKeybinds();
if(newKey) {
this.settings.serverMuteHotkey = newKey;
this.registerKeybinds();
this.saveSettings();
} else PluginUtilities.showToast("You did not input anything!", { type : "error" });
}, { description : "For when you feel like being a hero.", global : true }), this.getName());
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createKeybindInput("server deafen nate", this.settings.serverDeafenHotkey, newKey => {
this.unregisterKeybinds();
if(newKey) {
this.settings.serverDeafenHotkey = newKey;
this.registerKeybinds();
this.saveSettings();
} else PluginUtilities.showToast("You did not input anything!", { type : "error" });
}, { description : "For when you need to talk behind Nate's back.", global : true }), this.getName());
NeatoLib.Settings.pushChangelogElements(this);
}, 0);
return NeatoLib.Settings.Elements.pluginNameLabel(this.getName());
}
saveSettings() {
NeatoLib.Settings.save(this);
}
onLibLoaded() {
NeatoLib.Updates.check(this);
this.settings = NeatoLib.Settings.load(this, {
displayUpdateNotes : true,
muteHotkey : "Alt + N",
serverMuteHotkey : "Shift + Alt + N",
serverDeafenHotkey : "Control + Alt + N"
});
NeatoLib.Events.onPluginLoaded(this);
//if(this.settings.displayUpdateNotes) NeatoLib.Changelog.compareVersions(this.getName(), this.getChanges());
this.registerKeybinds();
this.initialized = true;
this.onSwitch();
}
onSwitch() {
if(!this.initialized) return;
this.selectedServer = NeatoLib.getSelectedTextChannel();
this.selectedVoiceChannel = NeatoLib.getSelectedVoiceChannel();
}
registerKeybinds() {
let nate = "209024642697003008",
toggleLocalMute = NeatoLib.Modules.get("toggleLocalMute").toggleLocalMute,
isLocalMuted = NeatoLib.Modules.get("isLocalMute").isLocalMute,
serverActionModule = NeatoLib.Modules.get(["setServerMute", "setServerDeaf"]),
getVoiceStates = NeatoLib.Modules.get("getVoiceStates").getVoiceStates;
NeatoLib.Keybinds.registerGlobal(this.settings.muteHotkey, () => {
toggleLocalMute(nate);
if(isLocalMuted(nate)) NeatoLib.showToast("I got ya, fam!", "success");
else NeatoLib.showToast("You're gonna regret that.", "error");
});
NeatoLib.Keybinds.registerGlobal(this.settings.serverMuteHotkey, () => {
if(this.selectedServer && this.selectedVoiceChannel) {
let voiceStates = getVoiceStates(this.selectedServer.id);
if(voiceStates[nate] == undefined) {
NeatoLib.showToast("Nate is not here, you're safe!", "success");
return;
}
serverActionModule.setServerMute(this.selectedServer.id, nate, !voiceStates[nate].mute);
if(!voiceStates[nate].mute) NeatoLib.showToast("You should be proud!", "success");
else NeatoLib.showToast("Sick fuck!", "error");
}
});
NeatoLib.Keybinds.registerGlobal(this.settings.serverDeafenHotkey, () => {
if(this.selectedServer && this.selectedVoiceChannel) {
let voiceStates = getVoiceStates(this.selectedServer.id);
if(voiceStates[nate] == undefined) {
NeatoLib.showToast("Nate is not here, you're safe!", "success");
return;
}
serverActionModule.setServerDeaf(this.selectedServer.id, nate, !voiceStates[nate].deaf);
if(!voiceStates[nate].deaf) NeatoLib.showToast("That Nate kid is an idiot.", "success");
else NeatoLib.showToast("Shut up guys!", "error");
}
});
}
unregisterKeybinds() {
NeatoLib.Keybinds.unregisterGlobal(this.settings.muteHotkey);
NeatoLib.Keybinds.unregisterGlobal(this.settings.serverMuteHotkey);
NeatoLib.Keybinds.unregisterGlobal(this.settings.serverDeafenHotkey);
}
stop() {
this.unregisterKeybinds();
}
}