forked from Metalloriff/BetterDiscordPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoiceChatNotifications.plugin.js
292 lines (263 loc) · 7.9 KB
/
VoiceChatNotifications.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
/**
* @name VoiceChatNotifications
* @invite yNqzuJa
* @authorLink https://github.com/Metalloriff
* @donate https://www.paypal.me/israelboone
* @website https://metalloriff.github.io/toms-discord-stuff/
* @source https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/VoiceChatNotifications.plugin.js
*/
module.exports = (() =>
{
const config =
{
info:
{
name: "VoiceChatNotifications",
authors:
[
{
name: "Metalloriff",
discord_id: "264163473179672576",
github_username: "metalloriff",
twitter_username: "Metalloriff"
}
],
version: "3.0.1",
description: "Displays notifications when users join/leave, mute/unmute, deafen/undeafen, or are moved in the voice channel you're in.",
github: "https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/VoiceChatNotifications.plugin.js",
github_raw: "https://raw.githubusercontent.com/Metalloriff/BetterDiscordPlugins/master/VoiceChatNotifications.plugin.js"
},
defaultConfig:
[
{
type: "category",
id: "log",
name: "notification settings",
collapsible: true,
shown: true,
settings:
[
{
type: "switch",
id: "connections",
name: "Show join/leave notifications",
value: true
},
{
type: "switch",
id: "selfMute",
name: "Show mute/unmute notifications",
value: true
},
{
type: "switch",
id: "selfDeafen",
name: "Show deafen/undeafen notifications",
value: true
},
{
type: "switch",
id: "moved",
name: "Show user channel move notifications",
value: true
},
{
type: "switch",
id: "mute",
name: "Show server mute/unmute notifications",
value: true
},
{
type: "switch",
id: "deafen",
name: "Show server deafen/undeafen notifications",
value: true
},
{
type: "switch",
id: "selfVideo",
name: "Show user video notifications",
value: true
},
{
type: "switch",
id: "selfStream",
name: "Show user stream notifications",
value: true
},
{
type: "switch",
id: "supressInDnd",
name: "Disable notifications while in do not disturb",
value: true
}
]
}
],
changelog:
[
{
type: "fixed",
title: "3.0.1 bug fix",
items:
[
"Fixed the plugin"
]
},
{
type: "fixed",
title: "3.0 rewrite",
items:
[
"This plugin has been rewritten, if you experience any new bugs, please contact me.",
"Please note that all settings have been reset and you will have to reconfigure them."
]
},
{
type: "added",
title: "new features",
items:
[
"Added user video notifications.",
"Added user stream notifications."
]
}
]
};
return !global.ZeresPluginLibrary ? class
{
constructor() { this._config = config; }
getName = () => config.info.name;
getAuthor = () => config.info.description;
getVersion = () => config.info.version;
load()
{
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () =>
{
require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (err, res, body) =>
{
if (err) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
});
}
});
}
start() { }
stop() { }
} : (([Plugin, Api]) => {
const plugin = (Plugin, Api) =>
{
const { WebpackModules, DiscordModules } = Api;
const { UserStore, ChannelStore, SelectedChannelStore, UserStatusStore } = DiscordModules;
const { getVoiceStates } = WebpackModules.getByProps("getVoiceStates");
return class VoiceChatNotifications extends Plugin
{
constructor()
{
super();
}
async showChangelog(footer)
{
try { footer = (await WebpackModules.getByProps("getUser", "acceptAgreements").getUser("264163473179672576")).tag + " | https://discord.gg/yNqzuJa"; }
finally { super.showChangelog(footer); }
}
getSettingsPanel = () => this.buildSettingsPanel().getElement();
onStart()
{
this.loop = setInterval(() => this.main(), 500);
}
main()
{
const vcid = SelectedChannelStore.getVoiceChannelId();
const vc = vcid == null ? null : ChannelStore.getChannel(vcid);
if (vc == null)
return;
const me = UserStore.getCurrentUser();
const states = getVoiceStates(vc.guild_id);
if (UserStatusStore.getStatus(me.id) != "dnd" || !this.settings.log.supressInDnd)
{
for (let state of Object.values(states))
{
const user = UserStore.getUser(state.userId);
const channel = ChannelStore.getChannel(state.channelId);
if (state.userId == me.id || this.states == null || user == null || channel == null)
continue;
const o = { silent: true, icon: user.getAvatarURL() };
if (this.states[state.userId] == null)
{
if (this.settings.log.connections)
{
new Notification(`${user.username} joined ${channel.name == "" ? "the call" : channel.name}`, o);
}
}
else
{
const lastState = this.states[state.userId];
const diff = Object.keys(state).filter(k => state[k] != lastState[k]);
if (this.settings.log.moves && lastState.channelId != state.channelId)
{
new Notification(`${user.username} moved to ${channel.name}`, o);
continue;
}
for (let d of diff)
{
const v = state[d];
let m = null;
switch (d)
{
case "selfMute":
m = `${user.username} ${v ? "muted" : "unmuted"} themselves`;
break;
case "selfDeafen":
m = `${user.username} ${v ? "deafened" : "undeafened"} themselves`;
break;
case "mute":
m = `${user.username} was ${v ? "muted" : "unmuted"}`;
break;
case "deafen":
m = `${user.username} was ${v ? "deafened" : "undeafened"}`;
break;
case "selfVideo":
m = `${user.username} ${v ? "enabled" : "disabled"} their video`;
break;
case "selfStream":
m = `${user.username} ${v ? "started a" : "stopped their"} stream`;
break;
}
if (m != null && this.settings.log[d] == true)
{
new Notification(m, o);
}
}
}
}
if (this.states != null)
{
for (let state of Object.values(this.states))
{
const user = UserStore.getUser(state.userId);
const channel = ChannelStore.getChannel(state.channelId);
if (state.userId == me.id || this.states == null || user == null || channel == null)
continue;
const o = { silent: true, icon: user.getAvatarURL() };
if (states[state.userId] == null && this.settings.log.connections)
{
new Notification(`${user.username} disconnected from ${channel.name == "" ? "the call" : channel.name}`, o);
}
}
}
}
this.states = states;
}
onStop()
{
clearInterval(this.loop);
}
}
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();