-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.js
679 lines (566 loc) · 19.8 KB
/
bot.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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
var cron = require('cron');
//var axios = require('axios');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: process.env.BOT_TOKEN,
autorun: true
});
// guild battle
/////////////////////////////////////////////////////////////////////
/*
var guild_battle = new cron.CronJob({
cronTime: '00 23 * * 6',
onTick: function() {
bot.sendMessage({
to: '404465250033991694',
message: '**GUILD BATTLE IS STARTING**'
});
},
start: true,
timeZone: 'America/New_York'
});
*/
// cooking contest
/////////////////////////////////////////////////////////////////////
var chef_examination_1 = new cron.CronJob({
cronTime: '00 13,23 * * 6',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Chef Exam is starting on channel 3'
});
},
start: true,
timeZone: 'America/New_York'
});
/*
var cooking_contest_1 = new cron.CronJob({
cronTime: '00 23 * * 6',
onTick: function() {
bot.sendMessage({
to: '404465250033991694',
message: 'Chef Exam is starting on channel 3'
});
},
start: true,
timeZone: 'America/New_York'
});
*/
// preliminary and final jousting
/////////////////////////////////////////////////////////////////////
var pre_jousting_time_1 = new cron.CronJob({
cronTime: '00 01 * * 1-6',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Preliminary Jousting begins'
});
},
start: true,
timeZone: 'America/New_York'
});
var pre_jousting_time_2 = new cron.CronJob({
cronTime: '00 22 * * 1-6',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Preliminary Jousting begins'
});
},
start: true,
timeZone: 'America/New_York'
});
var final_jousting_time = new cron.CronJob({
cronTime: '00 22 * * 7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Finals for Jousting begins on channel 2'
});
},
start: true,
timeZone: 'America/New_York'
});
// other raids
/////////////////////////////////////////////////////////////////////
var yeti_raid_1 = new cron.CronJob({
cronTime: '30 16,20 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Yeti Raid will be starting in Physis'
});
},
start: true,
timeZone: 'America/New_York'
});
var giant_sandworm_raid_1 = new cron.CronJob({
cronTime: '00 13,02 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Giant Sandworm Raid will be starting @ Central Muyu Desert'
});
},
start: true,
timeZone: 'America/New_York'
});
var giant_sandworm_raid_1B = new cron.CronJob({
cronTime: '00 13,02 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '554150587705458708',
message: 'Giant Sandworm Raid will be starting @ Central Muyu Desert'
});
},
start: true,
timeZone: 'America/New_York'
});
// dragon raids
/////////////////////////////////////////////////////////////////////
var red_dragon_raid_1 = new cron.CronJob({
cronTime: '00 19,00 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Red Dragon Raid will be starting @ Raspa Volcano'
});
},
start: true,
timeZone: 'America/New_York'
});
var red_dragon_raid_1T = new cron.CronJob({
cronTime: '00 19,00 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '440665629620699138',
message: 'Red Dragon Raid will be starting @ Raspa Volcano'
});
},
start: true,
timeZone: 'America/New_York'
});
var red_dragon_raid_1B = new cron.CronJob({
cronTime: '00 19,00 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '554150587705458708',
message: 'Red Dragon Raid will be starting @ Raspa Volcano'
});
},
start: true,
timeZone: 'America/New_York'
});
var white_dragon_raid_1 = new cron.CronJob({
cronTime: '30 14,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'White Dragon Raid will be starting @ Flightless Bird Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var white_dragon_raid_1T = new cron.CronJob({
cronTime: '30 14,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '440665629620699138',
message: 'White Dragon Raid will be starting @ Flightless Bird Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var white_dragon_raid_1T = new cron.CronJob({
cronTime: '30 14,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '554150587705458708',
message: 'White Dragon Raid will be starting @ Flightless Bird Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var black_dragon_raid_1 = new cron.CronJob({
cronTime: '00 14,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Black Dragon Raid will be starting @ Scorpion Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var black_dragon_raid_1T = new cron.CronJob({
cronTime: '00 14,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '440665629620699138',
message: 'Black Dragon Raid will be starting @ Scorpion Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var black_dragon_raid_1B = new cron.CronJob({
cronTime: '00 14,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '554150587705458708',
message: 'Black Dragon Raid will be starting @ Scorpion Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var desert_dragon_raid_1 = new cron.CronJob({
cronTime: '30 13 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Desert Dragon Raid will be starting @ Sheep Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var desert_dragon_raid_1T = new cron.CronJob({
cronTime: '30 13 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '440665629620699138',
message: 'Desert Dragon Raid will be starting @ Sheep Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var desert_dragon_raid_1B = new cron.CronJob({
cronTime: '30 13 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '554150587705458708',
message: 'Desert Dragon Raid will be starting @ Sheep Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var desert_dragon_raid_2 = new cron.CronJob({
cronTime: '00 20 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Desert Dragon Raid will be starting @ Sheep Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var desert_dragon_raid_2T = new cron.CronJob({
cronTime: '00 20 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '440665629620699138',
message: 'Desert Dragon Raid will be starting @ Sheep Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var desert_dragon_raid_2B = new cron.CronJob({
cronTime: '00 20 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '554150587705458708',
message: 'Desert Dragon Raid will be starting @ Sheep Mark'
});
},
start: true,
timeZone: 'America/New_York'
});
var prairie_dragon_raid_1 = new cron.CronJob({
cronTime: '00 18,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '409032469959016449',
message: 'Prairie Dragon Raid will be starting @ Maiz Prairie'
});
},
start: true,
timeZone: 'America/New_York'
});
var prairie_dragon_raid_1T = new cron.CronJob({
cronTime: '00 18,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '440665629620699138',
message: 'Prairie Dragon Raid will be starting @ Maiz Prairie'
});
},
start: true,
timeZone: 'America/New_York'
});
var prairie_dragon_raid_1B = new cron.CronJob({
cronTime: '00 18,22 * * 1-7',
onTick: function() {
bot.sendMessage({
to: '554150587705458708',
message: 'Prairie Dragon Raid will be starting @ Maiz Prairie'
});
},
start: true,
timeZone: 'America/New_York'
});
// initializing the bot
/////////////////////////////////////////////////////////////////////
bot.on('ready', function (evt) {
bot.setPresence( {
game: { name: 'you play', type: 3 }
});
const { Client } = require('pg');
// configure the database connection string
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
client.connect();
//ALTER TABLE raw ALTER COLUMN id TYPE BIGINT;
//SELECT table_schema,table_name FROM information_schema.tables;
client.query('SELECT table_schema,table_name FROM information_schema.tables;', (err, res) => {
if (err) throw err;
for (let row of res.rows) {
console.log(JSON.stringify(row));
}
client.end();
});
});
// helper function: translates the dailies
/////////////////////////////////////////////////////////////////////
function translateDailies(vdaily) {
vdaily = vdaily.replace("\\ud0c8\\ud2f4 \\uc810\\ub839\\uc804 II", "Battle for Taillteann II");
vdaily = vdaily.replace("\\ud0c8\\ud2f4 \\uc810\\ub839\\uc804 I", "Battle for Taillteann I");
vdaily = vdaily.replace("\\ud0c8\\ud2f4 \\ubc29\\uc5b4\\uc804", "Taillteann Defensive Battle");
vdaily = vdaily.replace("\\ud3ec\\uc6cc\\ub974 \\ucee4\\ub9e8\\ub354 \\ud1f4\\uce58 II", "Defeat Fomor Commander II");
vdaily = vdaily.replace("\\ud3ec\\uc6cc\\ub974 \\ucee4\\ub9e8\\ub354 \\ud1f4\\uce58 I", "Defeat Fomor Commander I");
vdaily = vdaily.replace("\\uc0c8\\ub3c4\\uc6b0 \\uc704\\uc790\\ub4dc \\ud1f4\\uce58", "Defeat the Shadow Wizard");
vdaily = vdaily.replace("\\uc81c\\ubb3c", "Offering");
vdaily = vdaily.replace("\\uc815\\ucc30\\ubcd1 \\uad6c\\ucd9c", "Rescue the Scout");
vdaily = vdaily.replace("\\ub3c4\\ubc1c", "Provocation");
vdaily = vdaily.replace("\\ub3c4\\ub80c\\uc758 \\ubd80\\ud0c1", "Dorren's Request");
vdaily = vdaily.replace("\\uadf8\\ub4e4\\uc758 \\ubc29\\uc2dd", "Their Method");
vdaily = vdaily.replace("\\uadf8\\ub9bc\\uc790 \\uc138\\uacc4\\uc758 \\uc720\\ud669\\uac70\\ubbf8", "The Sulfur Spider inside Shadow Realm");
vdaily = vdaily.replace("\\ud30c\\ub974\\ud640\\ub860\\uc758 \\uc720\\ub839", "Ghost of Partholon");
vdaily = vdaily.replace("\\ud3ec\\uc6cc\\ub974\\uc758 \\uc2b5\\uaca9", "Fomor Attack");
vdaily = vdaily.replace("\\ub610 \\ub2e4\\ub978 \\uc5f0\\uae08\\uc220\\uc0ac\\ub4e4", "The Other Alchemists");
vdaily = vdaily.replace("\\ub0a8\\uc544\\uc788\\ub294 \\uc5b4\\ub460", "Lingering Darkness");
vdaily = vdaily.replace("\\ub4f1 \\ub4a4\\uc758 \\uc801", "Enemy Behind");
vdaily = vdaily.replace("\\uadf8\\ub9bc\\uc790\\uac00 \\ub4dc\\ub9ac\\uc6b4 \\ub3c4\\uc2dc", "Shadow Cast City");
vdaily = vdaily.replace(/["]+/g, "");
return vdaily;
}
/*bot.on("presenceUpdate", (oldMember, newMember) => {
if(oldMember.presence.status !== newMember.presence.status){
console.log(`${newMember.user.username} is now ${newMember.presence.status}`);
}
});*/
// pick up lines
/////////////////////////////////////////////////////////////////////
var pick_up_lines = [
'Are you a magician? Because whenever I look at you, everyone else disappears!',
'I am not a photographer, but I can picture me and you together.',
'Are you religious? Because you are the answer to all my prayers.',
'You do not need keys to drive me crazy.',
'Is it hot in here or is it just you?',
'Hello. Cupid called. He wants to tell you that he needs my heart back.'
];
// greeting users (optional)
/////////////////////////////////////////////////////////////////////
bot.on("presence", function (user, userid, status, gameid) {
bot.sendMessage({
to: '535282907074396161',
message: "username: " + JSON.stringify(user) + " / " + JSON.stringify(userid) + " / status: " + status + " / gameid: " + gameid
});
if (status == "online") {
switch (user) {
case "Finley":
bot.sendMessage({
to: '404465250033991694',
message: "You're alive! Welcome back!!"
});
break;
}
}
});
// sending messages to discord
/////////////////////////////////////////////////////////////////////
bot.on('message', function (user, userID, channelID, message, evt) {
const { Client } = require('pg');
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
if (channelID == '409032469959016449') return;
// the bot will listen for messages that will start with `!`
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
case 'flirt':
var randomInt = Math.floor(Math.random() * Math.floor(5))
var line = pick_up_lines[randomInt];
bot.sendMessage({
to: channelID,
message: '~ ' + line + ' ~'
});
break;
case 'wd-lure':
/* bot.on('message', message => {
message.channel.send("Consult the following Infographic on White Dragon Luring strategy", {
files: ["https://photos.app.goo.gl/Bv9jB22ygLMGCEGc9"]
});
});
*/
bot.sendMessage({
to: channelID,
message: 'Consult the following Infographic on White Dragon Luring strategy: https://photos.app.goo.gl/Bv9jB22ygLMGCEGc9'
});
break;
case 'dailies':
case 'daily':
var url = "https://mabi-api.sigkill.kr/get_todayshadowmission/2018-1-26?ndays=1";
bot.sendMessage({
to: channelID,
message: 'Work in progress...!'
});
break;
case 'help':
bot.sendMessage({
to: channelID,
message: '`commands will always begin with the exclamation mark! then ping, flirt, dailies, daily, help, roll, time, raid, contact`'
});
break;
case 'contact':
bot.sendMessage({
to: channelID,
message: '`this bot is self-hosted and in no way official tool for nexon, and is still work in progress. you can contact **Pandurx** for more information or report any issues relating to the bot`'
});
break;
case 'flip':
var coin = '';
if ( Math.floor(Math.random() * Math.floor(100)) > 50 ) {
coin = 'heads';
} else {
coin = 'tails';
}
bot.sendMessage({
to: channelID,
message: 'You flipped ' + coin + '.'
});
break;
case 'roll':
bot.sendMessage({
to: channelID,
message: 'You rolled ' + Math.floor(Math.random() * Math.floor(100)) + ' ... '
});
break;
case 'future':
/*axios.get('https://api.github.com/repos/pandurx/pandurx-bot/issues?state=open')
.then(function (response) {
bot.sendMessage({
to: channelID,
message: 'CURRENT ITEMS' + response
});
})
.catch(function (error) {
bot.sendMessage({
to: channelID,
message: 'NOPE! CURRENT ITEMS'
});
});*/
break;
case 'releases':
bot.sendMessage({
to: channelID,
message: 'RELEASES'
});
break;
case 'time':
var time = new Date();
bot.sendMessage({
to: channelID,
message: 'The current time is ' + time.toLocaleString('en-US', {timeZone: 'America/New_York', hour: 'numeric', minute: 'numeric', hour12: false }) + ' EST'
});
break;
case 'raid':
var time = new Date();
bot.sendMessage({
to: channelID,
message: 'Prairie (6PM-6:30PM, 10PM-10:30PM) | Desert (1:30PM-2PM, 8PM-8:30PM) | Black (2PM-3PM, 10PM-11PM) EST'
});
break;
case 'get':
client.connect();
//'SELECT * FROM user_intro;'
//'INSERT INTO user_intro ('') VALUES (userID, "online", "whats new?", "boop");'
//{"user_id":1,"user_state":"online","user_data":"hello","user_command":"greet"}
var query_string = 'SELECT * FROM user_intro WHERE user_id = '+parseInt(userID)+';'
console.log('wquery ' + query_string);
client.query(query_string, (err, res) => {
if (err) throw err;
for (let row of res.rows) {
bot.sendMessage({
to: channelID,
message: JSON.stringify(row)
});
}
//console.log(JSON.stringify(row));
client.end();
});
break;
case 'set':
client.connect();
//'SELECT * FROM user_intro;'
//'INSERT INTO user_intro ('') VALUES (userID, "online", "whats new?", "boop");'
//{"user_id":1,"user_state":"online","user_data":"hello","user_command":"greet"}
var query_string = 'INSERT INTO user_intro (user_id, user_state, user_data, user_command) VALUES ('+parseInt(userID)+', \'heyoo\', \'whats new?\', \'boop\');'
console.log('wquery ' + query_string);
client.query(query_string, (err, res) => {
if (err) throw err;
client.end();
});
bot.sendMessage({
to: channelID,
message: 'hey this is still in progress..' + userID// + process.env.DATABASE_URL
});
break;
case 'update':
bot.sendMessage({
to: channelID,
message: 'April 15 2019 9:20PM EDT'
});
break;
// Just add any case commands if you want to..
}
}
});