-
Notifications
You must be signed in to change notification settings - Fork 4
/
AuroraGSI.plugin.js
278 lines (253 loc) · 8.95 KB
/
AuroraGSI.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
//META{"name":"AuroraGSI","website":"http://www.project-aurora.com/","source":"https://github.com/Popat0/Discord-GSI/blob/master/AuroraGSI.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%BetterDiscordplugins");
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.
'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.
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@*/
function getModule (props) {
return BdApi.findModuleByProps.apply(null, props);
}
module.exports = class AuroraGSI {
getName () {
return 'AuroraGSI';
}
getDescription () {
return 'Sends information to Aurora about users connecting to/disconnecting from, mute/deafen status';
}
getVersion () {
return '2.3.0';
}
getAuthor () {
return 'Popato, DrMeteor, AAGaming';
}
getChanges () {
return {
'1.0.0' :
`
Initial version.
`,
'1.0.1' :
`
Added conditions for only reacting to local user.
`,
'1.0.2' :
`
Removed isBeingCalled.
Removed redundant loop.
`,
'1.0.3' :
`
Updated the CDN for the library.
`,
'1.1' :
`
Made the state only be sent if it changed.
`,
'2.0' :
`
Version bump to stop the update prompt derping.
`,
'2.1.0':
`
Allow to track mute/deafen statuses outside voice channels.
Fix unread status for Enhanced Discord users.
Actually fix self-updating loop
`,
'2.1.1':
`
Fix "being_called" boolean so it's now usable (triggers when user calls and getting called in DMs)
`,
'2.2.0':
`
Rewrite a bunch of stuff
`,
'2.3.0':
`
Ported rewrite from AAGaming
`
};
}
getSelectedGuild () {
const channel = this.getChannel(this.channels.getChannelId())
return channel ? this.getGuild(channel.guild_id) : null;
}
getSelectedTextChannel () {
return this.getChannel(this.channels.getChannelId());
}
getSelectedVoiceChannel () {
return this.getChannel(this.channels.getVoiceChannelId());
}
getLocalStatus () {
return this.getStatus(this.getCurrentUser().id);
}
load () {}// legacy
start () {
this.json = {
provider: {
name: 'discord',
appid: -1
},
user:{
id: -1,
status: 'undefined',
self_mute: false,
self_deafen : false,
mentions: false,
unread_messages: false,
being_called: false
},
guild: {
id: -1,
name: ''
},
text: {
id: -1,
type: -1,
name: ''
},
voice: {
id: -1,
type: -1,
name: ''
}
};
// eslint-disable-next-line no-unused-expressions
this.lastJson;
this.getCurrentUser = getModule([ 'getUser', 'getUsers' ], false).getCurrentUser;
this.getStatus = getModule([ 'getApplicationActivity' ], false).getStatus;
this.getChannel = getModule([ 'getChannel' ], false).getChannel;
this.getGuild = getModule([ 'getGuild' ], false).getGuild;
this.channels = getModule([ 'getChannelId' ], false);
const { getUser } = getModule([ 'getUser' ], false),
voice = getModule([ 'isMute', 'isDeaf', 'isSelfMute', 'isSelfDeaf' ], false),
{ getCalls } = getModule([ 'getCalls' ], false),
{ getUnreadGuilds } = getModule([ 'getUnreadGuilds' ], false),
{ getTotalMentionCount } = getModule([ 'getTotalMentionCount' ], false),
isMute = voice.isMute.bind(voice),
isDeaf = voice.isDeaf.bind(voice),
isSelfMute = voice.isSelfMute.bind(voice),
isSelfDeaf = voice.isSelfDeaf.bind(voice);
/*
* { getChannel } = getModule([ 'getChannel' ], false), // we dont use this yet
* const { getVoiceStates } = getModule([ 'getVoiceState' ], false),
*/
this.updatetimer = setInterval(() => {
// eslint-disable-next-line consistent-this
const guild = this.getSelectedGuild();
const localUser = this.getCurrentUser();
const localStatus = this.getLocalStatus();
const textChannel = this.getSelectedTextChannel();
const voiceChannel = this.getSelectedVoiceChannel();
/*
* if (voiceChannel) {
* var voiceStates = getVoiceStates(voiceChannel.guild_id);
* } not implemented
*/
if (localUser && localStatus) {
this.json.user.id = localUser.id;
this.json.user.status = localStatus;
} else {
this.json.user.id = -1;
this.json.user.status = '';
}
if (guild) {
this.json.guild.id = guild.id;
this.json.guild.name = guild.name;
} else {
this.json.guild.id = -1;
this.json.guild.name = '';
}
if (textChannel) {
this.json.text.id = textChannel.id;
if (textChannel.type === 0) { // text channel
this.json.text.type = 0;
this.json.text.name = textChannel.name;
} else if (textChannel.type === 1) { // pm
this.json.text.type = 1;
this.json.text.name = getUser(textChannel.recipients[0]).username;
} else if (textChannel.type === 3) { // group pm
this.json.text.type = 3;
if (textChannel.name) {
this.json.text.name = textChannel.name;
} else {
let newname = '';
for (let i = 0; i < textChannel.recipients.length; i++) {
const user = textChannel.recipients[i];
newname += `${getUser(user).username} `;
}
this.json.text.name = newname;
}
}
} else {
this.json.text.id = -1;
this.json.text.type = -1;
this.json.text.name = '';
}
if (voiceChannel) {
if (voiceChannel.type === 1) { // call
this.json.voice.type = 1;
this.json.voice.id = voiceChannel.id;
this.json.voice.name = getUser(voiceChannel.recipients[0]).username;
} else if (voiceChannel.type === 2) { // voice channel
this.json.voice.type = 2;
this.json.voice.id = voiceChannel.id;
this.json.voice.name = voiceChannel.name;
}
} else {
this.json.voice.id = -1;
this.json.voice.type = -1;
this.json.voice.name = '';
}
this.json.user.self_mute = isSelfMute();
this.json.user.self_deafen = isSelfDeaf();
this.json.user.mute = isMute();
this.json.user.deafen = isDeaf();
this.json.user.unread_messages = false;
this.json.user.mentions = false;
this.json.user.being_called = false;
this.json.user.mentions = getTotalMentionCount();
this.json.user.unread_messages = Object.values(getUnreadGuilds()).length;
if (getCalls().filter((x) => x.ringing.length > 0).length > 0) {
this.json.user.being_called = true;
}
if (JSON.stringify(this.json) !== this.lastJson) {
this.lastJson = JSON.stringify(this.json);
this.sendJsonToAurora(this.json);
}
}, 100);
}
async sendJsonToAurora (json) {
fetch('http://localhost:9088/', {
method: 'POST',
body: JSON.stringify(json),
mode:'no-cors',
headers:{
'Content-Type': 'application/json'
}
})
.catch(error => console.log(`Aurora GSI error: ${error}`));
}
stop () {
clearInterval(this.updatetimer);
// this.unpatch();
this.ready = false;
}
};