-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·1901 lines (1742 loc) · 80.7 KB
/
index.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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// i'm so fucking sorry
// x. 2k18 02 16
// i'm even more sorry but i added the tipline function so i'm not
// x with lotus cobra
// 2k18 07 10
// it's currently on 1.0 and running fine on the server
// however there are a couple glitches and the code looks like ass
// i'm going to go through and take some stuff out
// and clean up the indents so it can be put on github
// x. 2k18 12 11
// added some more features and made it actually handle errors instead of just throwing exceptions
// x. 2k19 01 02
const datFolder = __dirname + '/data/';
const logFolder = datFolder + 'logs/';
const deetsFolder = datFolder + 'servers/'
const dataFolder = datFolder + 'config/';
const reactconfig = datFolder + 'react-config.json';
const globalconfig = datFolder + 'global-config.json';
const bridgeconfig = datFolder + 'bridge-config.json';
const badlistpath = datFolder + 'badlist.json';
const lockfilepath = __dirname + '/lock';
const versionid = "Electro-Magistrate v1.0";
const starttime = new Date().getTime();
const cloaklength = 18;
const film = "on";
const filmPostInterval = 10;
var filmOngoing = "0";
var loveFletcher = 0;
const fs = require('fs');
const os = require('os');
const path = require('path');
const http = require('http');
const https = require('https');
const disco = require('discord.js');
const now = require('moment');
const EventEmitter = require('events');
// class buffEmitter extends EventEmitter {}
// const buffemitter = new buffEmitter();
// const sqlite3 = require('sqlite3').verbose();
var v = (process.argv.indexOf('v') + process.argv.indexOf('-v') + 2);
var h = (process.argv.indexOf('h') + process.argv.indexOf('-h') + 2);
var dbg = (process.argv.indexOf('d') + process.argv.indexOf('-d') + 2);
var m = (process.argv.indexOf('m') + process.argv.indexOf('-m') + 2);
var w = (process.argv.indexOf('w') + process.argv.indexOf('-w') + 2);
var u = (process.argv.indexOf('u') + process.argv.indexOf('-u') + 2);
// Process command-line arguments into variables.
v = v ? 1 : 0;
dbg = dbg ? 1 : 0;
h = h ? 1 : 0;
m = m ? 1 : 0;
w = w ? 1 : 0;
u = u ? 1 : 0;
cbotlog(process.argv);
if (h) {
console.log(versionid + " / x. cinera 2k18");
console.log("Usage: node " + path.basename(__filename) + " [-d] [-h] [-m] [-v] [-w]")
console.log(" -d, debug Run in debug mode")
console.log(" -h, help Display help menu and exit")
console.log(" -m, multiple Run without aborting existing")
console.log(" already-running process detected")
console.log(" -v, verbose Run with verbose logging enabled")
console.log(" -u, ultraverb Log every single packet received")
console.log(" -w, weak Omit writing to lockfile so that")
console.log(" process will be killed by cronjob")
process.exit(0);
} // If help flag is set, print command flags and exit.
try { fs.mkdirSync(datFolder) } catch(e) {}
// Try to load configuration data. If it doesn't exist, create a blank template file.
try { configz = JSON.parse(fs.readFileSync(globalconfig))} catch (e) {
baseconfig = {
"bridges":"off",
"debate":"off",
"hottakes":"off",
"bigboss":{
"id":"x",
"username":"x",
"dispname":"x",
"note":"x"},
"bigserver":{
"id":"x",
"dispname":"x",
"note":"x"},
"bigchannel":{
"id":"x",
"dispname":"x",
"note":"x"},
"bigchamber":{
"id":"x",
"dispname":"x",
"note":"x"},
"filmchannel":{
"bosses":[],
"id":"000000000000000000",
"dispname":"x",
"note":"x"},
"lazylog":"off",
"lockfiletimeout":"60",
"lockfilewrite":"45"
};
fs.appendFileSync(globalconfig, JSON.stringify(baseconfig, null, ' '));
cbotlog("ERROR: No configuration file detected. Creating one now.");
configz = baseconfig;
} // Try to read file, create if absent.
var lazeLog = 0;
if (configz['lazylog'] === "on") {lazeLog = 1}
if (!m) {
const lockfiletimeout = configz.lockfiletimeout; // Number of seconds the program should wait after the last heartbeat to declare old instance dead
if (os.platform() == "win32") {
console.log("ERROR: You appear to be using Micro$haft Winblow$! :^(");
console.log(" Killing currently-running processes won't work.");
}
try {
seconds = ((new Date().getTime() - fs.statSync(lockfilepath).mtime) / 1000);
lock = JSON.parse(fs.readFileSync(lockfilepath));
} catch(e) {
var seconds = 8675309;
var lock = JSON.parse(-8675309)
fs.writeFileSync(lockfilepath, JSON.stringify(process.pid));
} // closes "try" block that either opens/scrapes or creates the lockfile.
if(seconds < lockfiletimeout) {
console.log("ERROR: " + path.basename(__filename) + " (PID " + lock + ") seems to be already running, as of");
console.log(" " + seconds.toFixed(1) + "s ago. It will be pronounced dead after " + lockfiletimeout + "s (" + (lockfiletimeout - seconds).toFixed(1) + "s left)");
process.exit(1); // Die with failure code
} // Kill process if the lock file has been updated in the last thirty seconds prior to Maggie being started.
else {
if ((os.platform() != "win32") && ((os.uptime() - seconds) > 0)){
try {
process.kill(lock, 'SIGKILL');
console.log("Killed ghost of previous instance.");
} catch(e) {
console.log("No previous instances terminated.");
} // closes catch for trying to kill
} // if you aren't running winblow$
} // if seconds are above the timeout
} // goes through lockfile check unless, for some reason, you've set the -m flag
if (!w) {
setInterval(function() {
fs.writeFileSync(lockfilepath, JSON.stringify(process.pid));
}, (1000 * configz['lockfilewrite']));
// As long as the program's running, it should be writing to the LOCKFILE every INTERVAL.
} // If no w: if weakmode is enabled it shouldn't write to the lockfile.
now.relativeTimeThreshold('ss', 1);
now.relativeTimeThreshold('s', 360);
now.relativeTimeThreshold('m', 360);
now.relativeTimeThreshold('h', 48);
now.relativeTimeThreshold('d', 300);
// Change thresholds for Moment to give more accurate times
console.log(date() + " || " + versionid + ' || INITIALIZING');
console.log("lock: " + lock + ", pid: " + process.pid);
fs.writeFileSync(lockfilepath, JSON.stringify(process.pid));
try { bridged = JSON.parse(fs.readFileSync(logFolder + "bridged.log"))} catch (e) {
bridged = {"1":"1"};
fs.writeFileSync(logFolder + "bridged.log", JSON.stringify(bridged));
console.log("ERROR: No bridge logs. Creating file.");
} // Try to read file, create if absent.
var bridging = {"1":"1"};
var baleeted = ["1"];
var examined = ["1"];
var flick = now.utc();
var flickrun = [1, 55, 55];
var flickname = ["Battletoads"];
var timeoutz = [];
var interCount = 0;
var lastInter = 0;
// Initialize deets folder and read a list of files from it
// An array that will be used to store all of this stuff so that it doesn't get garbage collected, I guess.
var allDiscos = [];
var allDeets = [];
var allBridges = [];
v && console.log("GLOBAL CONFIG LOADED");
try { fs.mkdirSync(logFolder) } catch(e) {}
try { fs.mkdirSync(deetsFolder) } catch(e) {}
try { fs.mkdirSync(dataFolder) } catch(e) {}
try { badlist = JSON.parse(fs.readFileSync(badlistpath))} catch (e) {
badlist = ['000000000000000000'];
fs.appendFileSync(badlistpath, JSON.stringify(badlist, null, ' '));
cbotlog("ERROR: No badlist detected. Creating empty file.");
} // Try to access badlist; create if absent.
v && cbotlog("LOG DIR: /" + configz['logdir'] + "/ || CONF DIR: /" + configz['deetsdir'] + "/");
var deezDeets = fs.readdirSync(deetsFolder);
console.log('CONF FILES: ' + deezDeets);
(dbg || v) && cbotlog("STARTING WITH " + (dbg ? "DEBUG " : "") + ((dbg * v) ? "AND " : "") + (v ? "VERBOSE " : "") + "MODE ENABLED");
(w || m) && cbotlog("(" + (m ? "MULTI " : "") + ((m * w) ? "AND " : "") + (w ? "WEAK " : "") + "PROCESS CONTROLS)");
var bridgefigz = 0;
try { bridgefigz = JSON.parse(fs.readFileSync(bridgeconfig))} catch (e) {}
if ((configz['bridges'] === "on") && bridgefigz) {
cbotlog("BRIDGING ENABLED (" + Object.keys(bridgefigz).length + ")");
// This is how you return the number of objects in a JSON object, I guess.
} // closes bridge setup
else { cbotlog("BRIDGING DISABLED"); } // closes else for the bridge setup
bridgeBuffer = {
'content':'!',
'usrname':'!',
'user_id':'!',
'dest_ch':'!',
'dest_sv':'!',
'attache':{},
}; // closes bridgeBuffer default JSON
setInterval(function() {
console.log(date());}, 30000);
var hts = "off";
if (configz['hottakes'] === 'on') {
hts = "on";
try { professions = JSON.parse(fs.readFileSync(datFolder + "goofy/professions.json"))} catch (e) {hts = "off";};
try { oppressed = JSON.parse(fs.readFileSync(datFolder + "goofy/oppressed.json"))} catch (e) {hts = "off";};
try { oppression = JSON.parse(fs.readFileSync(datFolder + "goofy/oppression.json"))} catch (e) {hts = "off";};
}
try {
goodmorning = JSON.parse(fs.readFileSync(datFolder + "goodmorning.json"));
var wakeup = "on";
} catch (e) {
var wakeup = "off";}
// this is where the magic happens. outer control loop iterated over all configs
for (var i = 0; i < deezDeets.length; i++){
// Initialize Discord connection
const disClient = new disco.Client();
// Connect to Discord API using credentials taken from the i-th file in the directory
const disFile = JSON.parse(fs.readFileSync(deetsFolder + deezDeets[i]));
const authDeets = disFile['token'];
var disBridges = {"nullenberg":"nullenborg"};
try { disClient.login(authDeets)
.catch(console.error);
}
catch (e) {
cbotlog('Authentication failure on ' + disFile['appellation']);
}
// If the global and local bridge flags are set...
if (configz['bridges'] === "on") {
if (bridgefigz[disFile['server_id']]) {
disFile['bridges'] = bridgefigz[disFile['server_id']];
console.log('Attempting connection (B:' + Object.keys(bridgefigz[disFile['server_id']]).length + ') to "' + disFile['appellation'] + '" (' + deetsFolder + deezDeets[i] + ')');
//console.log(disBridges);
} // closes "if there's any bridges for this server"'
else {
console.log('Attempting connection (B:0) to "' + disFile['appellation'] + '" (' + deetsFolder + deezDeets[i] + ')');
//console.log(disBridges);
} // closes first else for if bridging is enabled but no bridges exist
} // closes "if bridges are enabled globally + per server"
else {
console.log('Attempting connection (B:X) to "' + disFile['appellation'] + '" (' + deetsFolder + deezDeets[i] + ')');
//console.log(disBridges);
} // closes else for if they're disabled
// Cram the client object into allDiscos so that it can exist outside of this scope
allDiscos.push(disClient);
allDeets.push(disFile);
disClient.on('error', (errorEvent) => {
cbotlog(errorEvent.message);
})
// this is the startup routine that iterates over every client when it connects
disClient.on('ready', () => {
disServer = disClient.guilds.get(disFile['server_id']);
// creates an object, local to this scope, of the single guild named in the specific config file
// multiple config files can use the same authentication tokens.
// config files may only contain deets for one server, so each disFile only uses one server
var supMsg = "!";
if (wakeup === "on") {
if (!disClient.channels.get(goodmorning[1])) return;
disClient.channels.get(goodmorning[1]).send(goodmorning[2])
.then(message => {
console.log("Wew lad");
supMsg = message;
console.log("Wew lad");
})
.catch(console.log("asdf"));
}
disFile['client_id'] = disClient.user.id;
disFile['client_name'] = disClient.user.username;
if (disServer) {
disFile['server_name'] = disServer.name;
}
else {
cbotlog("Error: Cannot fetch server for " + disFile['server_id'] + " (" + disFile['appellation'] + ")");
}
cbotlog("Connected to \"" + disFile['appellation'] + "\": " + disFile['server_name'] + " (" + disFile['server_id'] + ") as " + disFile['client_name'] + " (" + disFile['client_id'] + ")");
try { fs.mkdirSync(dataFolder + disFile['server_id']) } catch(e) {}
// const secrets = JSON.parse(fs.readFileSync(dataFolder + disFile['server_id'] + "/secrets.json"));
// const sterces = reverseSecrets(secrets);
console.log("Server configuration loaded for " + disFile['appellation']);
try {
disFile['introed'] = JSON.parse(fs.readFileSync(dataFolder + disFile['server_id'] + "/introduced.json"));
console.log("Introduced users list loaded.");
setTimeout(function() {if (supMsg != "!") supMsg.react('🤝');}, 5000);
// 🤝 U+1F91D HANDSHAKE, decimal: 129309, HTML: 🤝
}
catch (e) {
console.log("No introed configuration found. Creating empty file.");
disFile['introed'] = ["0","0"];
fs.writeFileSync(dataFolder + disFile['server_id'] + "/introduced.json", JSON.stringify(disFile['introed'], null, ' '));
}
try {
disFile['reaccs'] = JSON.parse(fs.readFileSync(dataFolder + disFile['server_id'] + "/reaccs.json"));
console.log("React config loaded.");
setTimeout(function() {if (supMsg != "!") supMsg.react('👀');}, 5250);
//👀 U+1F440 EYES, decimal: 128064, HTML: 👀
}
catch (e) {
console.log(e);
console.log("No reaction configuration found. Creating empty file.");
disFile['reaccs'] = {"a":"a"};
fs.writeFileSync(dataFolder + disFile['server_id'] + "/reaccs.json", JSON.stringify(disFile['reaccs'], null, ' '));
}
try {
disFile['roles'] = JSON.parse(fs.readFileSync(dataFolder + disFile['server_id'] + "/roles.json"));
console.log("Role config loaded.");
setTimeout(function() {if (supMsg != "!") supMsg.react('👥');}, 5500);
//👥 U+1F465 BUSTS IN SILHOUETTE, decimal: 128101, HTML: 👥
}
catch (e) {
console.log(e);
console.log("No reaction configuration found. Creating empty file.");
disFile['roles'] = {"a":"a"};
fs.writeFileSync(dataFolder + disFile['server_id'] + "/roles.json", JSON.stringify(disFile['roles'], null, ' '));
}
setTimeout(function() {if (supMsg != "!" && disFile['anon'] === "on") supMsg.react('🕵');}, 5750);
// SLEUTH OR SPY' (U+1F575)
setTimeout(function() {if (supMsg != "!" && disFile['rot13'] === "on") supMsg.react('🕜');}, 6000);
// UNICODE: 1F55C CLOCK FACE ONE-THIRTY
setTimeout(function() {if (supMsg != "!" && disFile['film'] === "on") supMsg.react('🎞');}, 6250);
//🎞 U+1F39E FILM FRAMES, decimal: 127902, HTML: 🎞
setTimeout(function() {if (supMsg != "!" && disFile['bridges'] != "off") supMsg.react('🌉');}, 6500);
// Bridge At Night U+1F309
// 🌄 U+1F304 SUNRISE OVER MOUNTAINS, decimal: 127748, HTML: 🌄
setTimeout(function() {
//logUpAJson(disFile, ["token", "register_on_guild", "introed"]);
dbg && console.log(disFile['client_name']);
dbg && logInAJson(disFile, 'bridges');
if (supMsg != "!") {
fs.unlink(datFolder + "goodmorning.json", (err) => {
if (err) cbotlog(err);
else supMsg.react('🌄');
});
}
}, 7000);
for(var ds in Object.keys(disFile['reaccs'])) {
re = disFile['reaccs'];
ki = Object.keys(re)[ds];
if (ki === "a") return;
if (re[ki]['kill'] === "yes") return;
disClient.guilds.get(re[ki]['chat']).channels.get(re[ki]['chan']).fetchMessage(ki)
.then (message => {
// console.log(message.reactions.keys());
for(var dd in message.reactions.keys()) {
// console.log(message.reactions[dd]);
}
//console.log(message.reactions.find(x => x.Emoji.id === re[ki][')
})
.catch(console.error);
// disClient.guilds.get(disFile.reaccs[ds].
}
}); // this closes out the startup routine
// see: https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/coding-guides/raw-events.md
// that's what this is adapted from
disClient.on('raw', packet => {
u && console.log(date());
u && console.log(packet);
if(packet.t == 'PRESENCE_UPDATE') return;
if(packet.t === 'GUILD_MEMBER_UPDATE') {
// console.log(packet);
if (disFile['server_id'] === packet.d.guild_idbg && disFile['rolecatcher'] === "on") {
// console.log(packet.d.user.id);
disFile['roles'][packet.d.user.id] = packet.d.roles;
try {
fs.writeFileSync(dataFolder + disFile['server_id'] + "/roles.json", JSON.stringify(disFile['roles'], null, ' '));
// console.log("Roles saved.");
} catch (e) {console.log("Error: no roles json found.")}
} // if rolecatcher's on and it's on the monitored server
} // if it's a guild member update
if(packet.t === 'GUILD_MEMBER_REMOVE' && disFile['memberlog'] === "on") {
memberlog("REM: " + packet.d.guild_id + " / " + packet.d.user.id + " (" + packet.d.user.username + "#" + packet.d.user.discriminator + ")");
}
if(packet.t === 'GUILD_MEMBER_ADD') {
if (disFile['memberlog'] === "on") { memberlog("ADD: " + packet.d.guild_id + " / " + packet.d.user.id + " (" + packet.d.user.username + "#" + packet.d.user.discriminator + ")");}
console.log(packet);
// console.log(packet.d.user.id);
if (disFile['roles'][packet.d.user.id]) {
var newRoles = disFile['roles'][packet.d.user.id];
//console.log(newRoles);
// console.log(disClient.guilds.get(packet.d.guild_id).name);
setTimeout(function() {
for (var inc in newRoles) {
//console.log(newRoles[inc]);
disClient.guilds.get(packet.d.guild_id).members.get(packet.d.user.id).addRole(newRoles[inc])
}
}, 3000);
} // if there's a roles entry for the user id
} // if it's a guild member add
// this will re-emit events for emoji add/remove and deletions on non-cached messages
// basically it accounts for discord.js being stupid and not doing this
if (configz.sec) {
if(packet.t === 'VOICE_STATE_UPDATE' && packet.d.channel_id === configz.sec.orig) {
disClient.guilds.get(packet.d.guild_id).members.get(packet.d.user_id).addRole(configz.sec.role)
disClient.guilds.get(packet.d.guild_id).members.get(packet.d.user_id).setVoiceChannel(configz.sec.dest)
//console.log("illuminated");
}
if(packet.t === 'VOICE_STATE_UPDATE' && packet.d.channel_id === null) {
setTimeout(function() {
// console.log(disClient.guilds.get(packet.d.guild_id).members.get(packet.d.user_id));
disClient.guilds.get(packet.d.guild_id).members.get(packet.d.user_id).removeRole(configz.sec.role);
//console.log("rming illuminatus");
}, 1500);
}
}
if(packet.t == 'MESSAGE_CREATE') {
// Bridge config still exists here.
}
if (!['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE', 'MESSAGE_DELETE', 'MESSAGE_UPDATE', 'TYPING_START'].includes(packet.t)) return;
// if it's anything that we don't care about, gtfo this loop
if(packet.t == 'TYPING_START') {
return;
// not implemented yet
}
if(packet.t == 'MESSAGE_UPDATE') {
var channel = disClient.channels.get(packet.d.channel_id);
if (!packet.d.guild_id) return; // if it was a DM!
if (channel.lastMessageID != packet.d.id) return;
// This will only process a message if it's the most recent one in the channel.
dbg && console.log("Last message edited!");
examined.splice(examined.indexOf(packet.d.id), 1)
disClient.emit('messageDelete', {
'channel': disClient.channels.get(packet.d.channel_id),
'deleted': 'true',
'id': packet.d.id,
'type': 'DEFAULT',
'content': '0ldmessagebal33t',
'author': 'kilgore_trout',
'pinned': 'false',
'tts': 'false',
'nonce': 'n0tan0nce',
'system': 'false',
'embeds': [],
'attachments': [],
'createdTimestamp': 'false',
'editedTimestamp': 'false',
'reactions': 'false',
'mentions': 'false',
'webhookID': 'false',
'hit': 'false'
});
setTimeout(emitMessage, 1000, disClient);
function emitMessage (disClient) {
disClient.emit('message', disClient.channels.get(packet.d.channel_id).messages.get(packet.d.id));
}
return;
}
// dbg && console.log(packet);
var channel = disClient.channels.get(packet.d.channel_id);
if (['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE'].includes(packet.t)) {
// if (channel.messages.has(packet.d.message_id)) return;
// don't emit an event if the message is already cached
channel.fetchMessage(packet.d.message_id)
.then(message => {
const emoji = packet.d.emoji.id ? `${packet.d.emoji.name}:${packet.d.emoji.id}` : packet.d.emoji.name;
console.log(emoji);
// Emojis can have identifiers of name:id format, so we have to account for that case as well
const reaction = message.reactions.get(emoji);
//console.log(reaction);
// This gives us the reaction we need to emit the event properly, in top of the message object
if (packet.d.user_id === disClient.user.id) return;
// it shouldn't be processing stuff for its own reaccs
if (packet.t === 'MESSAGE_REACTION_ADD') {
// dbg && console.log(packet);
disClient.emit('bessageReactionAdd', reaction, disClient.users.get(packet.d.user_id));
}
if (packet.t === 'MESSAGE_REACTION_REMOVE') {
// dbg && console.log(packet);
if (!reaction) return;
disClient.emit('bessageReactionRemove', reaction, disClient.users.get(packet.d.user_id));
} // if it's an emoji raw
})
.catch(console.log("oop")); // closes what to do with the message once fetched
return;
} // closes "if it's a react or a remove react"
if (['MESSAGE_DELETE'].includes(packet.t)) {
dbg && console.log("'This message is cached' = " + channel.messages.has(packet.d.id));
if (channel.messages.has(packet.d.id)) return;
// don't emit an event if the message is already cached
channel.fetchMessage(packet.d.id)
.then(message => {
dbg && console.log('Message fetched.');
disClient.emit('messageDelete', message);
}) // if it does fetch a message
.catch(function() {
dbg && console.log('Emitting messageDelete');
disClient.emit('messageDelete', {
'channel': disClient.channels.get(packet.d.channel_id),
'deleted': 'true',
'id': packet.d.id,
'type': 'DEFAULT',
'content': '0ldmessagebal33t',
'author': 'kilgore_trout',
'pinned': 'false',
'tts': 'false',
'nonce': 'n0tan0nce',
'system': 'false',
'embeds': [],
'attachments': [],
'createdTimestamp': 'false',
'editedTimestamp': 'false',
'reactions': 'false',
'mentions': 'false',
'webhookID': 'false',
'hit': 'false'
}) // emits a message object to messageDelete
}); // closes what to do with the message once fetched
return;
} // if it's a delete raw
}); // closes out handler for raw event
disClient.on('bessageReactionAdd', (messageReaction, user) => {
var mcid = messageReaction.message.channel.id;
var mid = messageReaction.message.id;
if (messageReaction._emoji.name === "🕜") {
var pontent = messageReaction.message.content.substr(messageReaction.message.content.indexOf(">") + 3, 3000);
//console.log(pontent.length);
//if (pontent.length % 2 === 0) {return;}
//console.log(messageReaction.message.author.id);
if (messageReaction.message.author.id === "429368441577930753" && user.id === "429368441577930753") {
messageReaction.message.delete();
}
if (messageReaction.message.author.id != disClient.user.id) {return;}
user.send(messageReaction.message.channel.guild.members.get(user.id).displayName + ": " + rot13(pontent));
} // if it's rrrrr
if (disFile['reaccs'][mid]) {
if (disFile['reaccs'][mid]['kill'] === "yes") {
messageReaction.message.clearReactions();
} // closes if kill=yes
if (disFile['reaccs'][mid]['kill'] === "no") {
if (!disFile['reaccs'][mid][messageReaction._emoji.name]) {
messageReaction.remove(user)
return;
}
entry = disFile['reaccs'][mid][messageReaction._emoji.name];
messageReaction.message.channel.guild.members.get(user.id).addRole(entry['role']);
if (entry['keep'] === "no") {
setTimeout(function() {
messageReaction.remove(user)
}, 60000);
} // If "keep" is set to "no", remove the reaction.
// console.log(messageReaction);
} // closes if kill=no
} // closes if mid
if (disFile['bridges'][mcid] && disFile['bridges'][mcid]['active'] === "yes"){
dbg && cbotlog("Bridged from " + disFile['bridges'][mcid]['from_name'] + " / to: " + disFile['bridges'][mcid]['to_name']);
var bridgeBuffer = {
'message' : messageReaction.message.id,
'dest_ch' : disFile['bridges'][mcid]['to_id'],
'dest_sv' : disFile['bridges'][mcid]['to_svid'],
'reacced' : messageReaction._emoji.name,
'msgmode' : 'r',
'methode' : 'react',
};
for(var f = 0; f < Object.keys(allDiscos).length; f++){
if ((allDiscos[f].guilds.find(x => x.id === disFile['bridges'][mcid]['to_svid'])) != null) {
dbg && console.log('Emitting bridgedMessage for copy of ' + disFile['bridges'][mcid]['to_svname']);
allDiscos[f].emit('bridgedMessage', bridgeBuffer)
.catch( console.log("Error: could not emit bridged message"));
} // closes event emitter for when it finds the right disco
} // closes iterator for f
} // close check for bridge existence, activation and non-webhook post
}); // messageReactionAdd handler
disClient.on('bessageReactionRemove', (messageReaction, user) => {
var mcid = messageReaction.message.channel.id;
var mid = messageReaction.message.id;
if (disFile['reaccs'][mid]) {
if (!disFile['reaccs'][mid]['kill']) return;
if (disFile['reaccs'][mid]['kill'] === "no") {
entry = disFile['reaccs'][mid][messageReaction._emoji.name];
messageReaction.message.channel.guild.members.get(user.id).removeRole(entry['role']);
// console.log(messageReaction);
} // closes if kill=no
} // closes if mid
if (disFile['bridges'][mcid] && disFile['bridges'][mcid]['active'] === "yes"){
dbg && cbotlog("Bridged from " + disFile['bridges'][mcid]['from_name'] + " / to: " + disFile['bridges'][mcid]['to_name']);
var bridgeBuffer = {
'message' : messageReaction.message.id,
'dest_ch' : disFile['bridges'][mcid]['to_id'],
'dest_sv' : disFile['bridges'][mcid]['to_svid'],
'reacced' : messageReaction._emoji.name,
'msgmode' : 'd',
'methode' : 'deact',
};
for(var f = 0; f < Object.keys(allDiscos).length; f++){
if ((allDiscos[f].guilds.find(x => x.id === disFile['bridges'][mcid]['to_svid'])) != null) {
dbg && console.log('Emitting bridgedMessage for copy of ' + disFile['bridges'][mcid]['to_svname']);
allDiscos[f].emit('bridgedMessage', bridgeBuffer);
} // closes event emitter for when it finds the right disco
} // closes iterator for f
} // close check for bridge existence, activation and non-webhook post
}); // messageReactionAdd handler
disClient.on('messageDelete', message => {
// console.log(message);
if (examined.indexOf(message.id) != -1) return;
examined.push(message.id);
var mcid = message.channel.id;
dbg && console.log('messageDelete: ' + message.content);
dbg && console.log('Channel ID ' + message.channel.id + ' on guild ' + message.channel.guild.id);
if (disFile['bridges'][mcid] && disFile['bridges'][mcid]['active'] === "yes"){
dbg && cbotlog("Bridged from " + disFile['bridges'][mcid]['from_name'] + " / to: " + disFile['bridges'][mcid]['to_name']);
var bridgeBuffer = {
'message' : message.id,
'dest_ch' : disFile['bridges'][mcid]['to_id'],
'dest_sv' : disFile['bridges'][mcid]['to_svid'],
'msgmode' : 'k',
'methode' : 'kill',
};
for(var f = 0; f < Object.keys(allDiscos).length; f++){
if ((allDiscos[f].guilds.find(x => x.id === disFile['bridges'][mcid]['to_svid'])) != null) {
dbg && console.log('Emitting bridge-kill for copy of ' + disFile['bridges'][mcid]['to_svname']);
allDiscos[f].emit('bridgedMessage', bridgeBuffer);
} // closes event emitter for when it finds the right disco
} // closes iterator for d
} // close check for bridge existence, activation and non-webhook post
else {
dbg && console.log("Bridge not found for deleted message. Doing nothing.");
}
}) // end of handler for messageDelete ohh yeah
disClient.on('bridgedMessage', bridgeBuffer => {
serv = disClient.guilds.find(x => x.id === bridgeBuffer['dest_sv']);
dest = serv.channels.find(x => x.id === bridgeBuffer['dest_ch']);
if (!dest) {cbotlog("ERROR: Bridge " + bridgeBuffer['dest_ch'] + " (on " + bridgeBuffer['dest_sv'] + ") is bad!");}
else {
dbg && console.log('received bridge event for ' + bridged[bridgeBuffer['message']]);
// dbg && console.log(bridgeBuffer);
if(bridgeBuffer['msgmode'] == 'k' && bridged[bridgeBuffer['message']]) {
dbg && console.log("Del'd id " + bridgeBuffer['message'] + " [killing " + bridged[bridgeBuffer['message']] + "]");
dest.fetchMessage(bridged[bridgeBuffer['message']])
.then(message => {
setTimeout(baleet, 100, message);
function baleet(message) {
// console.log(baleeted);
dest.fetchMessage(bridged[bridgeBuffer['message']]);
if (bridged[bridgeBuffer['message']] && baleeted.indexOf(message.id) == -1) {
dbg && console.log("baleeting " + message.content);
message.delete();
} // if the message was bridged, go ahead and baleet it, and push its ID
} // defines function for baleeting
}) // ends handling of message from fetch
.catch(console.error);
} // if msgmode = k
if (badlist.indexOf(bridgeBuffer['user_id']) == -1) {
if(bridgeBuffer['msgmode'] == 'r' && bridged[bridgeBuffer['message']]) {
dbg && console.log("reacc'd id " + bridgeBuffer['message'] + " [reaccing " + bridged[bridgeBuffer['message']] + "]");
dest.fetchMessage(bridged[bridgeBuffer['message']])
.then(message => {
setTimeout(reacc, 100, message);
function reacc(message) {
dest.fetchMessage(bridged[bridgeBuffer['message']]);
if (bridged[bridgeBuffer['message']]) {
message.react(bridgeBuffer['reacced']);
} // if the message was bridged, go ahead and baleet it, and push its ID
} // defines function for baleeting
}) // ends handling of message from fetch
.catch(console.error);
} // if msgmode = r
if(bridgeBuffer['msgmode'] == 'd' && bridged[bridgeBuffer['message']]) {
dbg && console.log("deacc'd id " + bridgeBuffer['message'] + " [deaccing " + bridged[bridgeBuffer['message']] + "]");
dest.fetchMessage(bridged[bridgeBuffer['message']])
.then(message => {
setTimeout(deacc, 100, message);
function deacc(message) {
dest.fetchMessage(bridged[bridgeBuffer['message']]);
if (bridged[bridgeBuffer['message']]) {
dbg && console.log("reaccing " + message.content);
// var meacts = message.reactions.get(bridgeBuffer['reacced']);
// console.log(message.reactions);
var meacts = message.reactions.get(bridgeBuffer['reacced']);
dbg && console.log(meacts);
// console.log(meacts);
meacts.remove();
} // if the message was bridged, go ahead and baleet it, and push its ID
} // defines function for baleeting
}) // ends handling of message from fetch
.catch(console.error);
} // if msgmode = r
// dest.send("<" + bridgeBuffer['usrname'] + "> " + bridgeBuffer['content']);
dbg && console.log('Sending bridged message with code ' + bridgeBuffer['msgmode'] + " / " + bridgeBuffer['methode']);
if (bridgeBuffer['msgmode'] == "w" || bridgeBuffer['msgmode'] == "e") {
// I expect to put some regex modification of the content string here.
// Mentions have a couple dumb behaviors at the moment.
if (typeof bridgeBuffer['content'] === 'string') {
bridgeBuffer['content'] = bridgeBuffer['content'].replace(/@everyone/g, "@\u200beveryone").replace(/@here/g, "@\u200bhere");
}
} // if msgmode is "w" or "e"
if(bridgeBuffer['msgmode'] == "w") {
//console.log(bridgeBuffer['message']);
// var disHook = new Discord.WebhookClient("Webhook ID", "Webhook Token");
dest.fetchWebhooks()
.then(hooks => {
var sentImages = 0;
sendEmbed = [];
bridgeBuffer['attache'].forEach(item => {
// dest.send("<" + bridgeBuffer['usrname'] + "> " + item.url);
sendEmbed.push(item.url);
sentImages++;
}); // for each attachment...
var rightHook = hooks.find(x => x.id === bridgeBuffer['hook_id']);
var nameToSend = bridgeBuffer['user_un'];
if (serv.members.find(x => x.id === bridgeBuffer['user_id']) != null) {
nameToSend = serv.members.find(x => x.id === bridgeBuffer['user_id']).displayName;
}
if (nameToSend.length === 1) nameToSend = nameToSend + ".";
//avatar_url: bridgeBuffer['user_av'],
//rightHook.edit("blanku", bridgeBuffer['user_av'])
//.then(rightHook => {
if (bridgeBuffer['strip'] === "no") {
rightHook.send(bridgeBuffer['content'], {
"username": nameToSend,
"avatarURL": bridgeBuffer['user_av'],
"files": sendEmbed
}); } else {
rightHook.send(bridgeBuffer['content'], {
"username": nameToSend,
"avatarURL": bridgeBuffer['user_av']
}); }
}) // closes THEN HOOKS
.catch(console.error);
} // closes "if msg mode = w"
if(bridgeBuffer['msgmode'] == "e") {
sendEmbed = {
color: bridgeBuffer['user_cl'],
author: {
name: bridgeBuffer['user_dn'],
icon_url: bridgeBuffer['user_av']
},
description: bridgeBuffer['content'] + " ",
image: {}
}
var sentImages = 0;
bridgeBuffer.attache.forEach(item => {
// dest.send("<" + bridgeBuffer['usrname'] + "> " + item.url);
sendEmbed.image = {"url": item.url};
dest.send({embed: sendEmbed});
sendEmbed.description = " "; // Has to go after the dest.send because the first send will have the text in it!
sentImages++;
}); // for each attachment...
if (sentImages == 0) {dest.send({embed: sendEmbed})} // If no attachments, just send the embed off.
} // closes "if msg mode = e"
} // closes "if user isn't on badlist"
} // closes "if the bridge isn't bad"
}) // closes event handler for bridgedMessage event
// THE REAL MEAT AND POTATOES OF IT ALL: message handler
disClient.on('message', message => {
if (!message) return;
dbg && console.log("message");
var server = 0;
if (message.guild) server = message.guild;
var isBigBoss = 0;
var isFilmBoss = 0;
if (message.author.id === configz['bigboss']['id']) isBigBoss = 1;
if (disFile['film']) {
if (!disFile['filmchannel']) {
if (disFile['filmchannel']['bosses']) {
if (disFile['filmchannel']['bosses'].indexOf(message.author.id) != -1) isFilmBoss = 1;
}
}
}
var gotMsg = message.content;
if (message.content.search(/^<pid /) != -1 && isBigBoss === 1) {
if (message.content.substring(5, message.content.indexOf(">")) != process.pid) {
gotMsg = "";
return;
} else {
message.reply("Executing on PID " + process.pid);
gotMsg = message.content.slice(message.content.indexOf(">") + 2);
}
}
if (message.content.search(/^<!pid /) != -1 && isBigBoss === 1) {
if (message.content.substring(6, message.content.indexOf(">")) === process.pid) {
gotMsg = "";
return;
} else {
message.reply("Executing on PID " + process.pid);
gotMsg = message.content.slice(message.content.indexOf(">") + 2);
}
}
if ((gotMsg.search(/^pid$/) != -1) && (isBigBoss == 1)) {
message.reply(process.pid);
} // print pid
if (server == 0 && message.author.id != disClient.user.id && (isFilmBoss + isBigBoss) >= 1) {
//console.log("test");
if (disFile['arm'] && (isBigBoss == 1)) {}
else {disFile['arm'] = 1;}
if (gotMsg.search(/^arm/) != -1 && isBigBoss == 1) {
if (gotMsg.search(/^arm\+\+/) != -1) {
disFile['arm'] = disFile['arm'] + 1; } // Add one to arm count.
if (gotMsg.search(/^arm\-\-/) != -1) {
disFile['arm'] = disFile['arm'] - 1; } // Reduce arm count by 1.
if (gotMsg.search(/^arm 0/) != -1) {
disFile['arm'] = 0; } // Disarm entirely.
if (gotMsg.search(/^arm x/) != -1) {
disFile['arm'] = 99999999; } // Mass arm.
message.reply("Arm count: " + disFile['arm']);
} // if it's modifying arm...
if ((gotMsg.search(/^die/) != -1) && (isBigBoss == 1)) {
if (disFile['arm'] < 1){
message.reply("Error code NUI: not armed");
} // If unarmed.
else{process.abort();} // This kills the Electro-Magistrate.
} // closes code for "die"
if (gotMsg.search(/^purge/) != -1 && (isBigBoss == 1)) {
if (disFile['arm'] < 1){
message.reply("Error code NUI: not armed");
}
else{
disFile['arm'] = disFile['arm'] - 1;
if (gotMsg.substring(6,24) == gotMsg.substring(6,23)){
message.reply("Invalid channel ID string.");
disFile['arm']++;
}
else{
var fetchid = gotMsg.substring(6,24);
var todelete = gotMsg.substring(25,36);
if (todelete != parseInt(todelete, 10)) {todelete = 1}
message.reply("Arm count: " + disFile['arm'] + " / Fetch ID: " + fetchid + " (" + todelete + " messages)");
fetchChannel = disClient.channels.find(x => x.id === fetchid);
if (fetchChannel) {
message.reply("Server: " + fetchChannel.guild.name + " / Channel: " + fetchChannel.name);
if (todelete != 1) {fetchChannel.bulkDelete(todelete, 1);}
else {console.log(fetchChannel.lastMessageID);
fetchChannel.fetchMessage(fetchChannel.lastMessageID)
.then(message => message.delete())
.catch(console.error);
} // if toDelete = 1
} // Closes if on the fetch channel being real.
} // Closes on if the string is valid.
} // Closes on if it's armed.
} // Closes on if it detects a purge.
if (gotMsg.search(/^brankav/) != -1 && isBigBoss == 1) {
if (disFile['arm'] < 1){
message.reply("Error code NUI: not armed");
} // If it's unarmed.
else{
disFile['arm'] = disFile['arm'] - 1;
var blanktar = fs.readFileSync(__dirname + "/data/b64.png");
message.reply("Current (" + disClient.user.avatar + "): " + disClient.user.avatarURL);
setTimeout(function() {disClient.user.setAvatar(blanktar)}, 10000);
setTimeout(function() {message.reply("New: (" + disClient.user.avatar + "): " + disClient.user.avatarURL)}, 20000);
} // Closes on if it's armed.
} // Closes on if it detects an avatar reset.
if (gotMsg.search(/^bad/) != -1 && (isBigBoss == 1)) {
if (disFile['arm'] < 1){
message.reply("Error code NUI: not armed");
} // If unarmed.
else{
disFile['arm'] = disFile['arm'] - 1;
if(gotMsg.search(/^bad\+/) != -1) {
if((gotMsg.substring(5,22) != gotMsg.substring(5,21)) && (gotMsg.substring(5,23) == gotMsg.substring(5,24))) {
badlist.push(gotMsg.substring(5,23));
} // Add user ID to badlist.
else {
message.reply("Error: this isn't a user ID");
} // If user ID is invalid.
} // closes if "bad+"
if(gotMsg.search(/^bad\-/) != -1) {
if((gotMsg.substring(5,22) != gotMsg.substring(5,21)) &&(gotMsg.substring(5,23) == gotMsg.substring(5,24))) {
if(badlist.indexOf(gotMsg.substring(5,23)) != -1) {
badlist.splice(badlist.indexOf(gotMsg.substring(5,23)), 1);
}
else { message.reply("Error: ID not in badlist"); }
}
else { message.reply("Error: this isn't a user ID");}
} // closes if "bad-"
message.reply("```\n" + badlist + "```");
fs.writeFileSync(__dirname + '/data/badlist.json', JSON.stringify(badlist, null, ' '));
} // Closes on if it's armed.
} // Closes on if it detects a badlist command.
if (gotMsg.search(/^film cancel/) != -1 && (isFilmBoss == 1) && film == "on") {
for(var i = 0; i < Object.keys(timeoutz).length ; i++) {
// console.log(timeoutz[i]);
clearTimeout(timeoutz[i]);
}
message.reply("Canceled outstanding timeouts.");
timeoutz = [];
}
if (gotMsg.search(/^film set/) != -1 && (isFilmBoss == 1) && film == "on") {
dateString = gotMsg.substring(9,34);
flick = now.utc(dateString);
// message.reply(dateString + " (" + flickname + ")");
disClient.guilds.get(disFile['server_id']).channels.get(disFile['filmchannel']['id']).send(now.utc(dateString).fromNow());
intervals = [1800, 1200, 600, 300, 180, 120, 60, 30, 20, 10, 5, 4, 3, 2, 1, 0];
intervalmsg = {
"1800":"**Thirty minutes until showtime!**",
"1200":"**Thirty minutes until showtime!**",
"600":"**Ten minutes until showtime!**",
"300":"**Five minutes until showtime!**",
"180":"**Three minutes until showtime!**",
"120":"**Two minutes until showtime!**",
"60":"**One minute until showtime!**",
"30":"**- 0:30**",
"20":"**- 0:20**",
"10":"**- 0:10**",
"5":"**- 0:05**",
"4":"**- 0:04**",
"3":"**- 0:03**",
"2":"**- 0:02**",
"1":"**- 0:01**"
};
timerinc = 0;
for (var i = 0; i < intervals.length; i++){
console.log(timerinc);
flack = now(flick);
flack.subtract({hours: 0, minutes: 0, seconds: intervals[i]});
intToStart = 0 - now.utc().diff(flack);
if (intToStart > 0) {
timeoutz.push(setTimeout(function () {
console.log(timerinc + " way before");
console.log("the thing is now + " + intervals[timerinc] + " with timeout " + intToStart);
if(intervalmsg[intervals[timerinc]] && intervals[timerinc] != 0) {
disClient.guilds.get(disFile['server_id']).channels.get(disFile['filmchannel']['id']).send(intervalmsg[intervals[timerinc]]);
} // if interval message found
else {
disClient.guilds.get(disFile['server_id']).channels.get(disFile['filmchannel']['id']).send(intervals[timerinc] + " SECONDS UNTIL START!");
} // if specific message for interval not found
if(intervals[timerinc] == 0) {
disClient.guilds.get(disFile['server_id']).channels.get(disFile['filmchannel']['id']).send("**Now playing: " + flickname + "** (00:00:00 / " + twoPad(flickrun[1]) + ":" + twoPad(flickrun[2]) + ":" + twoPad(flickrun[3]) + ")");
} // if it's showtime
console.log(timerinc + " before");
timerinc++;
console.log(timerinc + " after");
}, intToStart)); // closes timeout
} // closes "if the timeout interval is a positive number, i.e. if it hasn't happened yet"
else {
timeoutz.push(setTimeout(function () {
timerinc++;
console.log(timerinc + " : " + intervals[timerinc]);
console.log(intervalmsg[intervals[timerinc]]);
}, 1)); // closes timeout
} // if the timeout interval is negative??
} // closes for loop
message.reply("Starting movie at: " + now.utc(flick).format() + " (" + now.utc(flick).format("dddd, MMMM Do YYYY, HH:mm:ss") + " UTC)");
var totalMins = (60 * flickrun[1]) + flickrun[2];
timerincr = 1;
for(var i = 1; i < totalMins; i += disFile['filmchannel']['postinterval']) {
console.log("Setting timeout for " + i + " minutes");
timeoutz.push(setTimeout(function() {
disClient.guilds.get(disFile['server_id']).channels.get(disFile['filmchannel']['id']).send("**Now playing: " + flickname + "** (" + twoPad(Math.floor(timerincr / 60)) + ":" + twoPad(timerincr) + " / " + twoPad(flickrun[1]) + ":" + twoPad(flickrun[2]) + ":" + twoPad(flickrun[3]) + ")");
if (timerincr == 1) timerincr = 0; // same as with "i" down below!