-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex_old.js
403 lines (329 loc) · 14.3 KB
/
index_old.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
const Discord = require("discord.js");
const rp = require('request-promise');
const cheerio = require('cheerio');
const _ = require('lodash');
const cron = require('node-cron');
const config = require("./data/config.json");
const commands = require("./js/commands");
const userstore = require("./js/userstore");
const constants = require("./js/constants");
const client = new Discord.Client();
const commandPrefix = "!";
userstore.loadUsers();
client.on("message", (message) => {
if (message.author.bot) return;
if (!message.content.startsWith(commandPrefix)) return;
const commandBody = message.content.slice(commandPrefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
// Print Command Information to Console
let date = new Date()
if (constants.commands.includes(command)) {
console.log(`[${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}] ${command} ${args} - sent by ${message.author.username}`);
}
let rsnCommands = ["setrsn", "rsn", "skills", "skillz", "stats", "daily", "gains", "gainz", "yesterday", "weekly", "alog"];
let itemCommands = ["ge"];
// Remove unwanted characters from argument
let cleanArgument = (s) => {
while (s.includes('"')) {
s = s.replace('"', '');
}
while (s.includes('{') || s.includes('}')) {
s = s.replace('{', '');
s = s.replace('}', '');
}
return s;
}
// Process RSN if command requires it
if (rsnCommands.includes(command)) {
var rsn = '';
// If no RSN was passed we need to check if one is saved
if (args.length === 0) {
rsn = userstore.getUser(message.author);
} else {
// Process RSN argument
rsn = args.join('+');
rsn = cleanArgument(rsn);
}
}
if (itemCommands.includes(command) && args.length > 0) {
var item = '';
item = args.join(' ')
item = cleanArgument(item);
}
switch (command) {
case "ping":
const timeTaken = Date.now() - message.createdTimestamp;
message.reply(`Pong! This message had a latency of ${timeTaken}ms.`)
.then(() => { })
.catch(constants.logError);
break;
case "info":
message.reply(commands.info(client.guilds.cache.size))
.then(() => { })
.catch(constants.logError);
break;
case "help":
message.reply(commands.help(commandPrefix))
.then(() => { })
.catch(constants.logError);
break;
case "setrsn":
case "rsn":
if (rsn !== undefined) {
userstore.saveUser(message.author, rsn);
message.reply(commands.rsn(rsn))
.then(() => { })
.catch(constants.logError);
} else {
message.reply(constants.noRSN)
.then(() => { })
.catch(constants.logError);
}
break;
case "skills":
case "skillz":
case "stats":
if (rsn === undefined) {
message.reply(constants.noRSN)
.then(() => { })
.catch(constants.logError);
break;
}
rp('https://apps.runescape.com/runemetrics/profile/profile?user=' + rsn + '&activities=10').then(function (json) {
const data = JSON.parse(json);
message.channel.send(commands.stats(data))
.then(() => { })
.catch(constants.logError);
}).catch(function (err) { });
break;
case "daily":
case "gains":
case "gainz":
case "yesterday":
case "weekly":
rp(`https://www.runeclan.com/user/${rsn}`).then(function (html) {
const $ = cheerio.load(html)
const data = $('tr');
if (rsn === undefined) {
message.reply(constants.noRSN)
.then(() => { })
.catch(constants.logError);
} else {
message.channel.send(commands.daily(data, rsn))
.then(() => { })
.catch(constants.logError);
}
}).catch(function (err) {
message.reply(constants.runeClanError);
constants.logError({
name: "RuneClan",
message: "User not found/tracked",
});
});
break;
case "rax":
case "spooder":
message.reply(commands.rax())
.then(() => { })
.catch(constants.logError);
break;
case "rago":
message.reply(commands.rago())
.then(() => { })
.catch(constants.logError);
break;
case "rots":
message.reply(commands.rots())
.then(() => { })
.catch(constants.logError);
break;
case "alog":
if (rsn === undefined) {
message.reply(constants.noRSN)
.then(() => { })
.catch(constants.logError);
break;
}
rp('https://apps.runescape.com/runemetrics/profile/profile?user=' + rsn + '&activities=10').then(function (json) {
const data = JSON.parse(json);
message.reply(commands.log(data))
.then(() => { })
.catch(constants.logError);
}).catch(function (err) { });
break;
case "vis":
rp('https://warbandtracker.com/goldberg/').then(function (html) {
const $ = cheerio.load(html)
const data = $('.worldTable');
message.reply(commands.vis(data))
.then(() => { })
.catch(constants.logError);
}).catch(function (err) { });
break;
case "merch":
rp('https://runescape.wiki/api.php?action=parse&disablelimitreport=1&format=json&prop=text&text=%7B%7BTravelling+Merchant%2Fapi%7Cformat%3Djson%7D%7D%7B%7BTravelling_Merchant%2Fapi%7Coffset%3D1%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D2%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D3%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D4%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D5%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D6%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D7%7Cformat%3Djson%7D%7D').then(function (json) {
const data = JSON.parse(json);
message.reply(commands.merch(data, true))
.then(() => { })
.catch(constants.logError);
}).catch(function (err) { });
break;
case "raven":
message.reply(commands.raven())
.then(() => { })
.catch(constants.logError);
break;
case "nemi":
rp('https://www.reddit.com/r/nemiforest/new.json?limit=1').then(function (json) {
const data = JSON.parse(json);
message.reply(commands.nemi(data))
.then(() => { })
.catch(constants.logError);
}).catch(function (err) { });
break;
case "portables":
rp('https://docs.google.com/spreadsheets/d/16Yp-eLHQtgY05q6WBYA2MDyvQPmZ4Yr3RHYiBCBj2Hc/gviz/tq?tqx=out:json').then(function (json) {
json = json.match(/google\.visualization\.Query\.setResponse\(([\s\S\w]+)\)/)[1];
const data = JSON.parse(json);
message.reply(commands.portables(data))
.then(() => { })
.catch(constants.logError);
}).catch(function (err) { message.reply(constants.portablesError) });
break;
case "vos":
rp('https://api.weirdgloop.org/runescape/vos').then(function (json) {
const data = JSON.parse(json);
commands.vos(data, message);
}).catch(function (err) { });
break;
case "ge":
if (item === undefined) {
message.reply(constants.noItem)
.then(() => { })
.catch(constants.logError);
constants.logError({
name: "Grand Exchange",
message: "Item not found",
});
break;
} else {
while(item.includes('+')) {
item = item.replace("+", "%2B");
}
}
rp('https://api.weirdgloop.org/exchange/history/rs/last90d?name=' + item).then(function (json) {
const data = JSON.parse(json);
commands.ge(data, message);
}).catch(
constants.logError({
name: "Grand Exchange",
message: "Item not found",
})
);
break;
}
});
client.login(config.BOT_TOKEN);
// Auto VOS
// This feature is currently exclusive to Dark Perception
cron.schedule('25 01 * * * *', () => {
let date = new Date();
console.log(`[${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}] Sending auto Voice of Seren`);
rp('https://api.weirdgloop.org/runescape/vos').then(function (json) {
const data = JSON.parse(json);
for (let i = 0; i < constants.vosChannels.length; i++) {
let channel = client.channels.cache.get(constants.vosChannels[i]);
let embeds = commands.vos(data, null)
// Remove previous VoS
channel.bulkDelete(10)
.then(() => { })
.catch(console.error);
// Send new VoS
channel.send(embeds.embed1);
channel.send(constants.vosRoles(embeds.embed1.title));
channel.send(embeds.embed2);
channel.send(constants.vosRoles(embeds.embed2.title));
}
}).catch(function (err) { });
});
// Auto Merch
// This feature is currently exclusive to Dark Perception
cron.schedule('35 00 00 * * *', () => {
let date = new Date();
console.log(`[${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}] Sending auto Merch`);
rp('https://runescape.wiki/api.php?action=parse&disablelimitreport=1&format=json&prop=text&text=%7B%7BTravelling+Merchant%2Fapi%7Cformat%3Djson%7D%7D%7B%7BTravelling_Merchant%2Fapi%7Coffset%3D1%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D2%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D3%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D4%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D5%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D6%7Cformat%3Djson%7D%7D%7B%7BTravelling+Merchant%2Fapi%7Coffset%3D7%7Cformat%3Djson%7D%7D').then(function (json) {
const data = JSON.parse(json);
for (let i = 0; i < constants.dailyChannels.length; i++) {
let channel = client.channels.cache.get(constants.dailyChannels[i]);
let merch = commands.merch(data, false);
// Send new Merch
channel.send(merch.embed);
for (let j = 0; j < merch.items.length; j++) {
if (merch.items[j].includes("Livid")) {
channel.send(constants.merchRoles[0])
} else if (merch.items[j].includes("Deathtouched")) {
channel.send(constants.merchRoles[1])
} else if (merch.items[j].includes("Reaper")) {
channel.send(constants.merchRoles[2])
} else if (merch.items[j].includes("Unstable")) {
channel.send(constants.merchRoles[3])
} else if (merch.items[j].includes("goebie") || merch.items[j].includes("Goebie")) {
channel.send(constants.merchRoles[4])
}
}
}
}).catch(function (err) { });
}, {
timezone: "Africa/Accra"
});
// Auto Vis
// This feature is currently exclusive to Dark Perception
// cron.schedule('00 00 01 * * *', () => {
cron.schedule('55 00 * * * *', () => {
let date = new Date();
console.log(`[${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}] Sending auto Vis`);
rp('https://warbandtracker.com/goldberg/').then(function (html) {
const $ = cheerio.load(html)
const data = $('.worldTable');
for (let i = 0; i < constants.dailyChannels.length; i++) {
let channel = client.channels.cache.get(constants.dailyChannels[i]);
let embed = commands.vis(data);
// Update at these hours of the day
let visHours = [1, 2, 3, 6, 9, 15, 21];
// Delete previous vis if not first vis of the day (1)
let date = new Date();
if (visHours.includes(date.getUTCHours()) && date.getUTCHours() > 1) {
channel.bulkDelete(1)
.then(() => { })
.catch(console.error);
}
if (visHours.includes(date.getUTCHours())) {
// Send new Vis
channel.send(embed);
}
}
}).catch(function (err) { });
}, {
timezone: "Africa/Accra"
});
// Auto Boss Rotation
// This feature is currently exclusive to Dark Perception
cron.schedule('25 00 00 * * *', () => {
let date = new Date();
console.log(`[${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}] Sending auto Rotation`);
for (let i = 0; i < constants.dailyChannels.length; i++) {
let channel = client.channels.cache.get(constants.dailyChannels[i]);
let raxEmbed = commands.rax();
let rotsEmbed = commands.rots();
// Remove previous auto Merch/Vis/Rax
channel.bulkDelete(10)
.then(() => { })
.catch(console.error);
channel.send(`Reminder to do your ${constants.portRole}`);
channel.send(raxEmbed);
channel.send(rotsEmbed);
}
}, {
timezone: "Africa/Accra"
});