-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignal.js
2159 lines (2069 loc) · 129 KB
/
signal.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
const bot = 'Signal';
const Discord = require( 'discord.js' );
//const commando = require( 'discord.js-commando' );//Not installed
//const sqlite = require( 'sqlite' );//Not installed
const fs = require( 'fs' );
const path = require( 'path' );
const fsSettings = 'settings.json'
const settings = require( path.join( __dirname, '../' + fsSettings ) );
const objTimeString = {
year: 'numeric', month: 'long', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
timeZone: 'America/New_York', timeZoneName: 'short' };
var strNow = ( new Date() ).toLocaleDateString( 'en-us', objTimeString );
const exec = require( 'child_process' ).exec;
const puppeteer = require( 'puppeteer' );
const strScreenShotPath = path.join( __dirname, '/' );
const unirest = require( 'unirest' );
// const later = require( 'later' );//Not installed
var idleMsg = false;
var enableSay = true;
var isDebug = settings[ bot ].onError.isDebugMode;
var isBotIdle = settings[ bot ].onError.isBotIdle;
var dcInfo = settings[ bot ].onError.dcInfo;
var dateCheckRoles = new Date( settings[ bot ].onError.dateCheckRoles );
var strLogChan = {
// '': { serverName: '', logChan: { name: undefined, id: undefined, canLog: false } },
'385498283738660875': { serverName: 'Geocaching', logChan: { name: 'bot-logs', id: '385596577596833803', canLog: true } },
'193758587284094978': { serverName: '/r/Geocaching', logChan: { name: 'off-topic', id: '193760602416611328', canLog: false } },
'192775085420052489': { serverName: 'The Cat Cabin', logChan: { name: 'bot-spam', id: '335080730742882304', canLog: true } },
'407643811796353035': { serverName: 'CentralJerseyGeocaching', logChan: { name: undefined, id: undefined, canLog: false } },
// '': { serverName: 'Synergy', logChan: { name: undefined, id: undefined, canLog: false } },
'448731649212022784': { serverName: 'GeocacheME', logChan: { name: 'bot-logs', id: '448733793558331392', canLog: true } },
// '': { serverName: 'Texas geocaching', logChan: { name: undefined, id: undefined, canLog: false } },
// '': { serverName: 'Geocaching', logChan: { name: undefined, id: undefined, canLog: false } },
// '': { serverName: 'New York City Geocaching!', logChan: { name: undefined, id: undefined, canLog: false } },
// '': { serverName: 'Unofficial Geocaching Discord server', logChan: { name: undefined, id: undefined, canLog: false } },
'558534076198420520': { serverName: 'Promoteing-Central™', logChan: { name: 'loging', id: '568909973824995328', canLog: true } },
'715558277022351361': { serverName: 'Boston geocaching', logChan: { name: 'signal-log', id: '715561344602210366', canLog: true } }
};
const rot = require( 'rot' );
const fsRank = 'rank.json';
const fsHints = 'hints.json';
var objTimeStringHQ = objTimeString;
objTimeStringHQ.timeZone = 'America/Los_Angeles';
objTimeStringHQ.hour12 = false;
async function sendMunzeeDiscordSocial( member, strOnReason = '' ) {
var objUserToSendTo = member.client.users.get( member.user.id );
const browser = await puppeteer.launch({headless:false});//DELETE
// const browser = await puppeteer.launch( );
const page = await browser.newPage( );
await page.goto( 'https://www.geocaching.com/track/details.aspx?id=7592234' );
var objTBData = await page.evaluate( async () => {
var strLastPageURL = document.getElementsByClassName( 'pager-last last' )[ 0 ].childNodes[ 0 ].href;
var intPages = strLastPageURL.slice( strLastPageURL.lastIndexOf( '=' ) + 1 );
const browser = await puppeteer.launch({headless:false});//DELETE
// const browser = await puppeteer.launch( );
const page = await browser.newPage( );
var intDiscoveries = 0;
do {
await page.goto( 'https://www.geocaching.com/track/details.aspx?id=7592234&page=' + intPages );
await page.evaluate( () => {
var domTable = document.getElementsByClassName( 'TrackableItemLogTable Table' );
var domEntries = domTable[ 0 ].querySelectorAll( 'tr.BorderTop' );
domEntries.forEach( entry => { if ( entry.innerText.match( 'discovered it' ) ) { intDiscoveries++; } } );
} );
intPages--;
} while ( intPages > 0 );
await browser.close();
var objTBData = {
strOwner: document.getElementById( 'ctl00_ContentBody_BugDetails_BugOwner' ).innerText,
dateReleased: document.getElementById( 'ctl00_ContentBody_BugDetails_BugReleaseDate' ).innerText,
intDiscoveries: intDiscoveries
}
return objTBData;
} );
await page.goto( 'https://www.geocaching.com/track/gallery.aspx?ID=7592234' );
var intPhotos = await page.evaluate( () => {
return document.getElementById( 'ctl00_ContentBody_GalleryItems_DataListGallery' ).querySelectorAll( 'img' ).length;
} );
objTBData.intPhotos = objGalleryData;
await browser.close();
var objDiscordTB = new Discord.RichEmbed()
.setColor( '#02884D' )
.setTitle( '**Congratulations!** You have found\nthe Geocaching Discord server!' )
.setURL( 'https://discord.me/Geocaching' )
.setThumbnail( member.guild.iconURL )
.setDescription(
'Please take a little time to check out our <#385622034622709760> channel and introduce yourself to everyone in <#385498283738660877>.\n\nTell us your player name, how long you\'ve been playing, and about your favorite Geocaches!\n\nFeel free to be Discoverer #' + ( objTBData.intCaptures + 1 ) + ' of the **' + objTBData.strName + '** trackable for your special find!' +
'\n\n**Released**: ' + ( new Date( objTBData.dateReleased ) ).toLocaleDateString( 'en-us', objTimeStringHQ ) +
'\n:camera_with_flash: **Photos**: [' + objTBData.intPhotos + ' photos](https://www.geocaching.com/track/gallery.aspx?ID=7592234)'
)
.setImage( 'attachment://MunzeeDiscord.png' );
objUserToSendTo.send( { embed: objMunzeeDiscord, files: [ { attachment: strScreenShotPath + 'Munzee Discord.png', name: 'MunzeeDiscord.png' } ] } )
.then( async msgSent => {
let objBotOwner = await member.client.users.get( settings[ bot ].owners[ 0 ] );
objBotOwner.send( 'I\'ve successfully DMed the **' + objTBData.strName + '** social to **' + objUserToSendTo + '#' + objUserToSendTo.discriminator + '**' + ( strOnReason !== '' ? strOnReason : '' ) );
} ).catch( async errDM => {
let objBotOwner = await member.client.users.get( settings[ bot ].owners[ 0 ] );
objBotOwner.send( 'I was unable to send the **' + objTBData.strName + '** social to **' + objUserToSendTo + '#' + objUserToSendTo.discriminator + '**' + ( strOnReason !== '' ? strOnReason : '' ) + ': __ ' + errDM + ' __' );
} );
}
const objDiscordTB = new Discord.RichEmbed()
.setTitle( 'TEST' )
.setDescription( 'You\'ve found it!' )
.setColor( '#02884D' )
.setThumbnail( 'https://cdn.discordapp.com/avatars/445799905177632768/a3629a8dd6a671c865a7c42f3553e904.png' );
function deconstructSnowflake( sfInput ) {
const { SnowflakeUtil } = require( 'discord.js' );
var thisSnowflake = SnowflakeUtil.deconstruct( sfInput );
if ( client.users.get( sfInput ) !== undefined ) {
if ( client.users.get( sfInput ).id === client.id ) {
thisSnowflake.type = 'userClient';
} else { thisSnowflake.type = 'user'; }
}
else if ( client.guilds.get( sfInput ) !== undefined ) {
thisSnowflake.type = 'guild';
}
else if ( client.channels.get( sfInput ) !== undefined ) {
switch ( client.channels.get( sfInput ).type ) {
case 'category' : thisSnowflake.type = 'categoryChannel'; break;
case 'text' : thisSnowflake.type = 'textChannel'; break;
case 'voice' : thisSnowflake.type = 'voiceChannel'; break;
default : thisSnowflake.type = 'undefinedChannel';
}
}
else {
thisSnowflake.type = 'undefined';
}
return thisSnowflake;
}
async function getDefaultChannel( guildID ){
if ( deconstructSnowflake( guildID ).type !== 'guild' ) {
throw new Error( 'Failed to specify a valid guildID snowflake for getDefaultChannel()' );
}//*/
const guild = client.guilds.get( guildID );
var intChannelIndex, objChannel;
var defaultChannel = { 'widget': false, 'systemChannelID': false, 'byPostition': false, 'byCreationIndex': false };
defaultChannel.widget = await msg.guild.fetchInvites().then( async invites => {
return await invites.filter( invite => invite.inviter !== undefined ).first().channel.id;
} );
if ( guild.channels.get( guild.systemChannelID ).permissionOverwrites.array()[ 0 ].deny === 0 ) {
defaultChannel.systemChannelID = guild.systemChannelID;
}
intChannelIndex = 0;
objChannel = {};
do {
objChannel = guild.channels.find( 'position', intChannelIndex );
defaultChannel.byPostition = objChannel.id;
intChannelIndex++;
} while ( objChannel.type !== 'text' && objChannel.permissionOverwrites.array()[ 0 ] !== undefined && objChannel.permissionOverwrites.array()[ 0 ].deny !== 0 );
intChannelIndex = 0;
objChannel = {};
do {
objChannel = guild.channels.array()[ intChannelIndex ];
defaultChannel.byCreationIndex = objChannel.id;
intChannelIndex++;
} while ( objChannel.type !== 'text' && objChannel.permissionOverwrites.array()[ 0 ] !== undefined && objChannel.permissionOverwrites.array()[ 0 ].deny !== 0 );
return defaultChannel;
}
function toBoolean( val ) {
val = ( typeof( val ) === 'string' ? val.toLowerCase() : val );
var arrTrue = [ true, 'true', 1, '1', 'on', 'yes' ];
return ( arrTrue.indexOf( val ) !== -1 ? true : false );
}
/*async function getGeocacherData( message, strHandleGC, objMessage ) {
// $( 'input#ctl00_ContentBody_FindUserPanel1_txtUsername' ).val( strUserName );
// $( 'input#ctl00_ContentBody_FindUserPanel1_GetUsers' ).click();
//
// IF success --> $( 'meta#ctl00_ogUrl' ).attr( 'content' ).startsWith( 'https://www.geocaching.com/profile/default.aspx?guid=' );
// ELSE -->$( 'meta#ctl00_ogUrl' ).attr( 'content' ).startsWith( 'https://www.geocaching.com/find/default.aspx' );
// var arrOptions = [];
// var domSelect = $( 'select#ctl00_ContentBody_FindUserPanel1_ddListUsers' ).children();
// domSelect.each( function( pos, domOption ) {
// arrOptions.push( { GSusername: domOption.innerText, GSguid: domOption.value } );
// } );
// console.log(arrOptions);
if ( !message ) {// Throw new Error if message is not defined.
throw new Error( 'object "message" is required to process getGeocacherData()' );
} else if ( !strHandleGC ) {// Forgot to give me a geocacher to work on, so I'm returning a pseudo-404
var objEmbed = new Discord.RichEmbed()
.setColor( '#FF0000' )
.setThumbnail( 'https://cdn.discordapp.com/attachments/355690877361979393/496803129225117717/dnf-page.png' )
.setDescription( 'You failed to specify a geocacher to look up.' );
if ( objMessage === undefined ) {
objMessage = await message.channel.send( '**No geocacher specified!**', { embed: objEmbed } );
}
objMessage.edit( '**No geocacher specified!** Returning error...', { embed: objEmbed } ).catch( errEdit => { console.error( 'Error updating getMemberData() message to indicate gathering "basic information".' ); } );
return {
error: 404,
avatar: 'https://cdn.discordapp.com/attachments/355690877361979393/496803129225117717/dnf-page.png'
};
}
else {
var objEmbed = new Discord.RichEmbed()
.setTitle( 'Fetching player data' );
if ( objMessage === undefined ) {
objMessage = await message.channel.send( 'Fetching player data, please wait...', { embed: objEmbed } );
}
const browser = await puppeteer.launch( { headless: false } );
const page = await browser.newPage( );
const basePage = 'https://www.geocaching.com/find/default.aspx';
await page.goto( basePage );
var objGetMemberPage = await page.evaluate( () => {
$( 'input#ctl00_ContentBody_FindUserPanel1_txtUsername' ).val( strHandleGC );
$( 'input#ctl00_ContentBody_FindUserPanel1_GetUsers' ).click();
} );// end page.evaluate()
// return objMember;
}
}//*/
var qPathTags = {
url: 'https://www.pathtags.com/api/v1.2/',
username: settings[ bot ].pathtag.username,
password: settings[ bot ].pathtag.password,
apikey: settings[ bot ].pathtag.apikey,
dataType: 'json',
authkey: '',
user_id: 'PathTags',
tagid: '5035',//Default "PathTag" PathTag ID
log: './PathTag logs/' + ( new Date() ).valueOf( ) + '.json'
};
function parsePathTagResponse( response ) {
return JSON.parse( response.body.trim() );
}
async function getPathTagId( strSerial ) {
var objPathTag = {};
var isSerial = /^[0-9a-zA-Z]+$/.test( strSerial );
if ( ( strSerial.length == 6 || strSerial.length == 7 ) && isSerial ) {
unirest.get( qPathTags.url + 'tag.php/gettagimg/' + strSerial + '/500/' + qPathTags.authkey + '?apikey=' + qPathTags.apikey )
.header( 'type', 'GET' )
.header( 'dataType', qPathTags.dataType )
.end( function ( objTagID ) {
objPathTag.statusCode = objTagID.statusCode;
objPathTag.response_status = JSON.parse( objTagID.body ).response_status;
objPathTag.tagid = JSON.parse( objTagID.body ).tagid;
if ( isDebug ) {
console.log( 'Completed processing tag with serial: ' + strSerial + ' and am returning objPathTag: \n' + JSON.stringify( objPathTag ) );
}
return objPathTag;
} );
} else {
objPathTag.statusCode = '200';
objPathTag.response_status = 'error';
objPathTag.response_body = 'Tag serial number is invalid, please check the number on the tag and try again.';// +
// '\n\tTo look up a PathTag by ID number, please use a `#12345` format instead.';
objPathTag.tagid = '5035';
if ( isDebug ) {
console.log( 'Completed processing tag with serial: ' + strSerial + ' and am returning objPathTag: \n' + JSON.stringify( objPathTag ) );
}
return objPathTag;
}
}//*/
function getCacheBasicDetails ( strCache ) {// NOT EVEN CLOSE TO READY!
const objIconTypes = { 2: 'traditional', 3: 'multicache', 4: 'virtual', 5: 'letterbox', 6: 'event', 8: 'mystery', 9: 'ape', 11: 'webcam', 12: 'locationless', 13: 'cito', 137: 'earthcache', 453: 'mega', 1304: 'gpsadventure', 1858: 'whereigo', 3653: '10years', 3773: 'ghq', 7005: 'giga' };
var objIcon = $( 'svg.icon.cache-icon > use' )[ 0 ].attributes[ 0 ].value.split( '/' );
objIcon = objIcon[ objIcon.length - 1 ];
if ( objIcon.split( '#' )[ 0 ] !== 'cache-types.svg' ) {
console.warn( 'objIcon is undefined with value of: %o', objIcon );
objIcon = undefined;
} else {
var strID = objIcon.split( '#' )[ 1 ];
var arrID = strID.split( '-' );
var intType = arrID[ 1 ];
if ( arrID.length === 3 ) {
var isArchived = ( arrID[ 2 ] === 'disabled' ? true : false );
}
objIcon = { strID: strID, arrID: arrID, intType: intType, strType: objIconTypes[ intType ], isArchived: ( isArchived ? isArchived : false ) };
}
console.log( 'objIcon is: %o', objIcon );
return objIcon;
}
/*function getPathTagInfo( intTagID ) {
var objPathTag = { 'tagid': intTagID, 'thumbUrl': 'http://www.pathtags.com/community/blueprints/' + intTagID + '/blueprint.jpg' };
// Get tag information using ID from getPathTagId( strSerial )
unirest.get( qPathTags.url + 'tag.php/getpublictagprofile/' + qPathTags.tagid + '/' + qPathTags.authkey + '?apikey=' + qPathTags.apikey )
.header( 'type', 'GET' )
.header( 'dataType', qPathTags.dataType )
.end( function ( objTagProfile ) {
objPathTag.statusCode = objTagProfile.statusCode;
objPathTag.response_status = JSON.parse( objTagProfile.body ).response_status;
objPathTag.tagid = JSON.parse( objTagProfile.body ).tagid;
} );
//* DEBUG
var thisLogFile = './Signal/PathTag logs/' + ( new Date() ).valueOf( ) + '-tagInfo.json';
var thisLogText = JSON.stringify( objPathTag );
fs.writeFile( thisLogFile, thisLogText, ( errWrite ) => {
if ( errWrite ) throw errWrite;
console.log( 'Created ' + thisLogFile + ' with ` ' + thisLogText + '`' );
} );
///// DEBUG
return objPathTag;
}
function getPathTagUserInfo( intUserID ) {
// Get user information
return 0;
}
function logPathTag( intTagID ){
// Log a tag using ID from getPathTagIdThumb( strSerial ) so the bot always has only one nontransferable tag
}
*/
function sendDM( message, recipient, strContent ) {
recipient
.send( strContent )
.then( dmSent => {
message.author.send( 'DM, ' + recipient + ' (' + recipient.tag + ') sent: `' + strContent + '`' );
} ).catch( dmErr => {
message.author.send( 'Unable to DM, ' + recipient + ' (' + recipient.tag + ') your message: `' + strContent + '`' );
} );
}
function hook( channel, title, message, color = 'FF0000', avatarURL = 'https://theme.zdassets.com/theme_assets/678183/af1a442f9a25a27837f17805b1c0cfa4d1725f90.png' ) {
if ( !channel ) return console.warn( 'Webhook channel not specified.' );
if ( !title ) return console.warn( 'Webhook title not specified.' );
if ( !message ) return console.warn( 'Webhook message not specified.' );
color = color.replace( /\s/g, '' );
avatarURL = avatarURL.replace( /\s/g, '' );
channel.fetchWebhooks()
.then( webhook => {
let foundHook = webhook.find( hook => { if ( hook.name === title || hook.name === 'Webhook' ) { return hook; } } );
if ( !foundHook ) {
channel.createWebhook( ( title || 'Webhook' ), avatarURL )
.then( async webhook => {
await webhook.send( '', {
'username': title,
'avatarURL': avatarURL,
'embeds': [ {
'color': parseInt( `0x${color}` ),
'description': message
} ]
} )
.catch( errSend => {
console.error( 'hook(): %o', errSend );
return channel.send( '**Check console, something went wrong with webhook.**' );
} );
webhook.delete();
} );
} else {
foundHook.send( '', {
'username': title,
'avatarURL': avatarURL,
'embeds': [ {
'color': parseInt( `0x${color}` ),
'description': message
} ]
} )
.catch( errSend => {
console.error( 'hook(): %o', errSend );
return channel.send( '**Check console, something went wrong with webhook.**' );
} );
}
} );
}
function clean( text ) {
if ( typeof( text ) === 'string' ) {
return text.replace( /`/g, '`' + String.fromCharCode( 8203 ) ).replace( /@/g, '@' + String.fromCharCode( 8203 ) );
} else {
return text;
}
}
const client = new Discord.Client();
client.login( settings[ bot ].token );
/* IRC relay start */
function meIRC( msgChan ) {
if ( msgChan.match( /ACTION(.*?)/ ) !== null ) {
msgChan = '*** _' + msgChan.replace( //g, '' ).substr( 7 ) + '_';
}
else {
msgChan = '*** :arrow_right: ' + msgChan;
}
return msgChan;
}
function meDiscord( msgIRC, noHash ) {
if ( noHash === undefined ) {
var noHash = false;
}
var arrMentions = msgIRC.match( /<@!?(\d*)>/gi );
if ( arrMentions !== null ) {
arrMentions.forEach( function( user, ndx ) {
var userID = user.replace( /[<@!>]/g, '' );
var userTag = client.users.get( userID ).tag;
if ( noHash ) {
userTag = client.users.get( userID ).username + '# ' + client.users.get( userID ).discriminator;
}
msgIRC = msgIRC.replace( user, '@' + userTag );
} );
}
var arrChannels = msgIRC.match( /<#(\d*)>/gi );
if ( arrChannels !== null ) {
arrChannels.forEach( function( chan, ndx ) {
var chanID = chan.replace( /[<#>]/g, '' );
var chanName = client.channels.get( chanID ).name;
msgIRC = msgIRC.replace( chan, '#' + chanName );
} );
}
/* Can't currently make the bot emote to IRC -- need to do some more digging. :\*/
if ( msgIRC.match( /_(.*?)_/ ) !== null ) {
msgIRC = msgIRC.substr( 1, ( msgIRC.length - 2 ) );
msgIRC = '\u0001ACTION ' + msgIRC + '\u0001';
}
else {
// pass it straight back through
}
//*/
return msgIRC;
}
const ircClient = require( 'node-irc' );
var clientIRC = new ircClient( 'irc.slashnet.org', 6667, 'Signal', 'discord.me/geocaching' );
// This decides the verbosity of the output, set to 1 as default
clientIRC.verbosity = 1; // 0 == Silent, 1 == Normal, 2 == Info
// This is set to false by default, prints out all raw server messages
clientIRC.debug = false;
clientIRC.on( 'ready', function () {
clientIRC.join( '#Geocaching-discord' );/* #Geocaching, */
// clientIRC.say( '#Geocaching-discord', 'I\'m connected to the channel!' );
} );
clientIRC.on( 'CHANMSG', function ( data ) {
if ( data.message.indexOf( 'williampitcock' ) == -1 && data.message.indexOf( 'kaniini' ) == -1 ) {
client.channels.get( '455532459728044032' ).send( '**' + data.nick + '*' + data.receiver + meIRC( data.message ) );
}
} );
clientIRC.on( 'PRIVMSG', function ( data ) {
settings[ bot ].owners.forEach( async function( ownerID, i ) {
var objOwner = await client.fetchUser( ownerID );
objOwner.send( 'I have received an IRC DM from **' + data.sender + '**: `' + data.message + '`' );
} );
clientIRC.say( data.nick, 'I\'m a bot, I don\'t understand your message. I\'ve forwarded your message to my owners.' );
} );
client.on( 'message', message => {
if ( message.channel.id === '455532459728044032' && message.author.id !== client.user.id ) {
clientIRC.say( '#Geocaching-discord', message.author.tag + ': ' + meDiscord( message.content ) );
}
} );
//clientIRC.connect();// COMMENT THIS LINE OUT WHEN DEBUGGING TO PREVENT IRC JOIN/PART SPAM! */
/*var cgeoGeocache = new ircClient( 'irc.freenode.net', 6667, 'Signal', 'discord.me/geocaching' );
cgeoGeocache.on( 'ready', function() {
cgeoGeocache.join( '#cgeo' );
} );
cgeoGeocache.on( 'CHANMSG', function ( dataCgeo ) {
client.channels.get( '457593331019546625' ).send( '**' + dataCgeo.nick + '*' + dataCgeo.receiver + meIRC( dataCgeo.message ) );
} );
cgeoGeocache.on( 'PRIVMSG', function ( dataCgeo ) {
settings[ bot ].owners.forEach( async function( ownerID, i ) {
var objOwner = await client.fetchUser( ownerID );
objOwner.send( 'IRC DM from **' + dataCgeo.sender + '** *(#cgeo)*: `' + dataCgeo.message + '`' );
} );
cgeoGeocache.say( dataCgeo.nick, 'I\'m a bot, I don\'t understand your message. I\'ve forwarded your message to my owners.' );
} );
client.on( 'message', message => {
if ( message.channel.id === '457593331019546625' && message.author.id !== client.user.id ) {
cgeoGeocache.say( '#cgeo', ( message.guild.members.get( message.author.id ).nickname || message.author.username ) + ': ' + meDiscord( message.content, true ) );
}
} );//*/
//cgeoGeocache.connect();// COMMENT THIS LINE OUT WHEN DEBUGGING TO PREVENT IRC JOIN/PART SPAM! */
var clientGeocache = new ircClient( 'irc.slashnet.org', 6667, 'ShoeMaker', 'Technical_13' );
clientGeocache.on( 'ready', function() {
clientGeocache.join( '#geocache' );
} );
clientGeocache.on( 'CHANMSG', function ( dataG ) {
client.channels.get( '456093333274624000' ).send( '**' + dataG.nick + '*' + dataG.receiver + meIRC( dataG.message ) );
} );
clientGeocache.on( 'PRIVMSG', function ( dataG ) {
settings[ bot ].owners.forEach( async function( ownerID, i ) {
var objOwner = await client.fetchUser( ownerID );
objOwner.send( 'IRC DM from **' + dataG.sender + '** *(#geocache)*: `' + dataG.message + '`' );
} );
} );
client.on( 'message', message => {
if ( message.channel.id === '456093333274624000' && message.author.id !== client.user.id ) {
clientGeocache.say( '#geocache', meDiscord( message.content ) );
}
} );
//clientGeocache.connect();// COMMENT THIS LINE OUT WHEN DEBUGGING TO PREVENT IRC JOIN/PART SPAM! */
/* IRC relay end */
client.on( 'ready', async () => {
// var objPrimaryOwner = await client.fetchUser( settings[ bot ].owners[ 0 ] );
// objPrimaryOwner.send( { embed: objDiscordTB } );
Promise.all( [
await unirest.get( qPathTags.url + 'user.php/doauth/' + qPathTags.username + '/' + qPathTags.password + '?apikey=' + qPathTags.apikey )
.header( 'type', 'GET' )
.end( async function ( objAuth ) {
var objAuth = JSON.parse( objAuth.body );
qPathTags.user_id = objAuth.user_id;
qPathTags.authkey = objAuth.authkey;
var strPathTags = JSON.stringify( qPathTags );
await fs.writeFile( qPathTags.log, strPathTags, ( errWrite ) => {
if ( errWrite ) { throw errWrite; }
console.log( 'Created ' + qPathTags.log + ' with ` ' + strPathTags + '`' );
} );
} ),
await client.user.setPresence( { status: settings[ bot ].status, afk: false, game: { name: settings[ bot ].game, type: 'PLAYING' } } )
] ).then( () => {
var readyTime = ( new Date() ).toLocaleDateString( 'en-US', objTimeString );
console.log( '\n' + readyTime + ':\t' + settings[ bot ].name + ' is now ready to accept commands.\n' )
if ( isDebug ) {
client.channels.get( settings[ bot ].debug[ 0 ] ).send( '_is now ready to accept commands at ' + readyTime + '._' );
}
} );
} );
client.on( 'disconnect', async ( dc ) => {
var disconnectTime = await ( new Date() ).toLocaleDateString( 'en-US', objTimeString );
objTempDB.dcInfo = await 'I\'ve been disconnected at ' + disconnectTime + ' with: ' + dc;
strTempDB = await JSON.stringify( objTempDB );
await fs.writeFile( fsTempDB, strTempDB, ( errWrite ) => {
if ( errWrite ) {
throw errWrite;
}
if ( isDebug ) {
dcInfo = '_has disconnected at ' + disconnectTime + ' with:_ ' + dc;
}
console.error( 'I\'ve been disconnected at ' + disconnectTime + ' with: ' + dc );
} );
} );
client.on( 'reconnecting', async ( rc ) => {
var reconnectTime = ( new Date() ).toLocaleDateString( 'en-US', objTimeString );
if ( isDebug ) {
if ( !dcInfo ) {
client.channels.get( settings[ bot ].debug[ 0 ] ).send( '_has reconnected at ' + reconnectTime + ' and is ready to accept commands:_ ' + ( rc ? rc : '' ) );
} else {
client.channels.get( settings[ bot ].debug[ 0 ] ).send( dcInfo + '\n_and has reconnected at ' + reconnectTime + ' and is ready to accept commands:_ ' + ( rc ? rc : '' ) );
}
}
console.log( 'Reconnected at ' + reconnectTime + '\n' + settings[ bot ].name + ' is now ready to accept commands: ' + ( rc ? rc : '' ) );
} );
client.on( 'error', ( err ) => {
if ( isDebug ) {
client.channels.get( settings[ bot ].debug[ 0 ] ).send( ':exclamation: _had an `error` at ' + strNow + ':_ `' + err + '`' );
}
console.error( '%s: ERROR: %o', strNow, err );
if ( err.code === 'ETIMEDOUT' ) {
console.error( '%o, failed to connect to the Internet on: %o', strNow, err.split( ' ' )[ ( err.split( ' ' ).length - 1 ) ] );
} else if ( err.code === 'ENOTFOUND' ) {
console.error( '%o, failed to connect to Discord on: %o', strNow, err.split( ' ' )[ ( err.split( ' ' ).length - 1 ) ] );
} else {
console.error( '%o: ERROR: %o', strNow, err );
}
} );
// Set status - If the bot hasn't done anything in 10 minutes, set status to idle.
client.setInterval( function() {
if ( client.user.presence.game.name && client.user.presence.game.name === 'restarting...' ) {
client.user.setPresence( settings[ bot ].game );// While we're at it checking things every 5 minutes... If the game wasn't updated on restart, try to set it again.
}
if ( client.user.localPresence.status !== 'idle' ) {
if ( isBotIdle ) {
if ( isDebug && idleMsg ) {
client.channels.get( settings[ bot ].debug[ 0 ] ).send( '_is idle_ :frowning2:' );
console.log( 'I am idle, no-one loves me!' );
}
client.user.setStatus( 'idle' );
} else {
if ( isDebug && idleMsg ) {
client.channels.get( settings[ bot ].debug[ 0 ] ).send( '_wasn\'t idle, but is now._ :frowning:' );
console.log( 'I wasn\'t idle, but I am now!' );
}
client.user.setStatus( 'online' );
isBotIdle = true;
}
}
}, 300000 );// 300000ms == 5m
/*client.setInterval( function() {// !rall
timeNow = ( new Date() ).toLocaleDateString( 'en-US', objTimeString );
exec( 'move /Y C:\Users\dfortier\.pm2\logs\*.log C:\Users\dfortier\.pm2\logs\backup', { windowsHide: true }, ( errExec, stdout, stderr ) => {
if ( errExec ) {
console.error( 'Error: %o', errExec );
return;
}
console.log( 'Result: %o', stdout );
console.log( 'stderr: %o', stderr );
} );
console.log( 'restart of all other bots at ' + timeNow );
exec( 'pm2 restart "DDObot" "LOTRObot" "Lazy Bastard" "greenie" "Vladdy"', { windowsHide: true }, ( errExec, stdout, stderr ) => {
if ( errExec ) {// "Gunther" "ShoeBot"
console.error( 'Error: %o', errExec );
return;
}
console.log( 'Result: %o', stdout );
console.log( 'stderr: %o', stderr );
} );
}, 432000000 );// 432000000 == 5 hours */
client.on( 'guildMemberAdd', ( member ) => {
var guildID = member.guild.id;
var objUser = member.user;
var strJoined = ( new Date( member.joinedTimestamp ) ).getHours();
var guildWelcomeMesages = {
'448731649212022784': {// Maine Geocaching
channel: '448731649212022786',//#general
role: '448733297397334021',//&Nano
message: 'Good ' + ( strJoined <= 11 ? 'morning' : ( strJoined <= 17 ? 'afternoon' : 'evening' ) ) + ', ' + objUser + '**#' + objUser.discriminator + '**! Welcome to the **' + member.guild.name + '** Discord server it\'s **' + ( new Date() ).toLocaleDateString( 'en-US', objTimeStringHQ ) + '** Geocaching HQ time!'
},
'385498283738660875': {// Geocaching
channel: '385498283738660877',//#general
role: '385598600467447808',//&Nano
message: 'Good ' + ( strJoined <= 11 ? 'morning' : ( strJoined <= 17 ? 'afternoon' : 'evening' ) ) + ', ' + objUser + '**#' + objUser.discriminator + '**! Welcome to the **' + member.guild.name + '** Discord server; the current Geocaching HQ time is: **' + ( new Date() ).toLocaleDateString( 'en-US', objTimeStringHQ ) + '**. If you share your, case specific, geocaching handle with us, `@Staff` can set you up with a matching nickname and some roles to have more acces to the server. <:Signal:398980726000975914>'
},
'407643811796353035': {// CentralJerseyGeocaching
channel: '407643812408590339',//#general
role: '420666987212177408',//&CacheNinja
message: 'Good ' + ( strJoined <= 11 ? 'morning' : ( strJoined <= 17 ? 'afternoon' : 'evening' ) ) + ', ' + objUser + '**#' + objUser.discriminator + '**! Welcome to the **' + member.guild.name + '** Discord server; the current Geocaching HQ time is: **' + ( new Date() ).toLocaleDateString( 'en-US', objTimeStringHQ ) + '**'
},
'193758587284094978': {// /r/Geocaching
channel: '193758587284094978',//#general
role: null,
message: 'Welcome to the **' + member.guild.name + '** Discord, ' + objUser + '**#' + objUser.discriminator + '**! Please introduce yourself with `!statbar [your, case sensitive, username here]` to get started!'
}
};
if ( guildWelcomeMesages[ guildID ] ) {
if ( isDebug ) {
settings[ bot ].debug.forEach( function ( channel ) {
client.channels.get( channel ).send( '*is processing a **`guildMemberCreate`** event for: __' + objUser + '**#' + objUser.discriminator + '**__ in __**' + member.guild.name + '**__.*' );
} );
}
var channel = member.guild.channels.get( guildWelcomeMesages[ guildID ].channel );
if ( !channel ) {
member.guild.channels.array().forEach( function ( defaultChannel ) {
if ( !channel && defaultChannel.type === 'text' ) {
channel = defaultChannel;
}
} );
}
if ( guildWelcomeMesages[ guildID ].blockSpam || true ) {
var strLowerUserName = objUser.username.toLowerCase();
var arrSpamNames = ( strLowerUserName.match( /(((discord|paypal)\.(gg|me))|(twitch\.tv)|((facebook|instagram|paypal|reddit|twitter|youtube)\.com?)|(bit.ly))\//i ) || [] );
if ( arrSpamNames.length >= 1 ) {
if ( member.guild.members.get( member.id ).bannable ) {
var strSpamFrom = arrSpamNames[ 0 ].replace( /\//, '' ).replace( /\.(com|gg|me)/, '' );
strSpamFrom = strSpamFrom.slice( 0, 1 ).toUpperCase() + strSpamFrom.slice( 1 );
member.ban( { days: 7, reason: strSpamFrom + ' invite spam(bot)' } )
.then( objBan => { console.log( '%s: Banned %s (%s) from %s (%s)', strNow, objUser.tag, objUser.id, member.guild.name, guildID ); } )
.catch( errBan => { console.error( '%s: Failed to ban %s (%s) from %s (%s): %o', strNow, objUser.tag, objUser.id, member.guild.name, guildID, errBan ); } );
} else {
console.error( '%s: Unable to ban %s (id:%s) from %s (id:%s)', strNow, objUser.tag, objUser.id, member.guild.name, guildID );
}
} else {
channel.send( guildWelcomeMesages[ guildID ].message );
if ( guildWelcomeMesages[ guildID ].role ) {
member.addRole( guildWelcomeMesages[ guildID ].role, 'Give our newest member the starter role!' ).catch( errAddRole => { console.error( '%s: Failed to assign %o role to %s (id:%s) in %s (id:%s): %o', strNow, guildWelcomeMesages[ guildID ].role, objUser.tag, objUser.id, member.guild.name, guildID, errAddRole ); } );
}
}
}
}
client.user.setStatus( 'online' );
isBotIdle = false;
} );
client.on( 'guildMemberRemove', ( member ) => {
var guildID = member.guild.id;
var objUser = member.user;
var guildGoodByeMesages = {
'385498283738660875': {//Geocaching
channel: '385596577596833803',//#bot-logs
message: 'Goodbye ' + objUser + '(- ' + objUser.tag + ' -)! **' + member.guild.name + '** will miss you!'
},
};
if ( guildGoodByeMesages[ guildID ] ) {
if ( isDebug ) {
settings[ bot ].debug.forEach( function ( channel ) {
client.channels.get( channel ).send( '*is processing a **`guildMemberRemove`** event for: __' + objUser + '**#' + objUser.discriminator + '**__ in __**' + member.guild.name + '**__.*' );
} );
}
var channel = member.guild.channels.get( guildGoodByeMesages[ guildID ].channel );
if ( !channel ) {
channel = member.guild.defaultChannel;console.log( 'No channel defined for [' + member.guild.name + ']. Using default channel of: ' + getDefaultChannel( guildID ) );
}
channel.send( guildGoodByeMesages[ guildID ].message );
}
client.user.setStatus( 'online' );
isBotIdle = false;
} );
client.on( 'messageUpdate', ( msgOld, msgNew ) => {
if ( msgOld.channel.type === 'dm' ) {
msgNew.channel.send( 'Editing your message does nothing to trigger me (except to make me tell you that editing your message does nothing to trigger me (except to make me tell you that editing your message does nothing to trigger me (...))).' );
} else if ( strLogChan[ msgNew.guild.id ] !== undefined ) {
if ( msgNew.content !== msgOld.content && strLogChan[ msgNew.guild.id ].logChan.canLog ) {
var msgAuthor = msgOld.author;
if ( client.user.id !== msgAuthor.id && !msgAuthor.bot ) {
var objMsgUpdate = new Discord.RichEmbed()
.setColor( '#F2D201' )
.setDescription( ':x: ' + ( msgOld || '**`NULL`**' )
+ '\n:white_check_mark: ' + ( msgNew || '**`NULL`**' ) );
client.channels.get( strLogChan[ msgNew.guild.id ].logChan.id ).send( ':warning: **' + msgAuthor.username + '**#' + msgAuthor.discriminator + ' edited a message in <#' + msgOld.channel.id + '>:', { embed: objMsgUpdate } );
}
}
} else {
msgNew.channel.send( msgNew.author + ', you seem to have modified your post and I don\'t have a log channel to log to yet! Please contact <@440752068509040660> to resolve this issue!' );
console.log( 'Unable to post messageUpdate event for `' + msgNew.guild.name + '` (ID:' + msgNew.guild.id + ') with no log channel defined.' );
}
} );
client.on( 'messageDelete', ( msg ) => {
if ( strLogChan[ msg.guild.id ] !== undefined ) {
var msgAuthor = msg.author;
if ( client.user.id !== msgAuthor.id && !msgAuthor.bot && strLogChan[ msg.guild.id ].logChan.canLog ) {
var objMsgDelete = new Discord.RichEmbed()
.setColor( '#FF0000' )
.setDescription( ( msg || '**`NULL`**' ) );
client.channels.get( strLogChan[ msg.guild.id ].logChan.id ).send( ':x: **' + msgAuthor.username + '**#' + msgAuthor.discriminator + '\'s message has been deleted from <#' + msg.channel.id + '>:', { embed: objMsgDelete } );
}
} else {
msg.channel.send( msg.author + ', you seem to have modified your post and I don\'t have a log channel to log to yet! Please contact <@440752068509040660> to resolve this issue!' );
console.log( 'Unable to post messageDelete event for `' + msg.guild.name + '` (ID:' + msg.guild.id + ') with no log channel defined.' );
}
} );
// Trigger commands
client.on( 'message', async message => {
const isBot = message.author.bot;
var guild = null;
var isOwner = ( settings[ bot ].owners.indexOf( message.author.id ) !== -1 ? true : false );
var strCrownID = '';
var isCrown = false;
var isAdmin = false;
if ( message.guild ) {
guild = message.guild;
const guildMember = guild.members.get( message.author.id );
strCrownID = await guild.owner.user.id;
isCrown = ( message.author.id === strCrownID ? true : false );
var objAdminRoles = [];
guild.roles.array().forEach( function( role, index ) {
if ( ( new Discord.Permissions( role.permissions ) ).has( 8 ) ) {
objAdminRoles[ objAdminRoles.length ] = role;
}
} );
objAdminRoles.forEach( function( role, index ) {
if ( ( role.members.keyArray() ).indexOf( message.author.id ) !== -1 || message.author.id === guild.ownerID ) {
isAdmin = true;
}
} );
let isNano = false, nanoRole = false, microRole = false;
if ( guild.id === '385498283738660875' ) {
nanoRole = await guild.roles.get( '385598600467447808' );
isNano = await ( nanoRole && ( nanoRole.members.keyArray() ).indexOf( message.author.id ) !== -1 ? true : false );
microRole = await guild.roles.get( '385598676896186369' );
if ( isNano ) {
guildMember.addRole( microRole, { reason: 'Nano member spoke for the first time!' } ).then( roleAdded => {
guildMember.removeRole( nanoRole, { reason: 'Nano member spoke for the first time!' } ).then( roleRemoved => {
message.reply( 'Congratulations! You\'ve been upsized from ' + nanoRole + ' for posting your first message on the server!' );
} ).catch( errAddRole => { console.error( ': FAILED to add micro role for ' + ( guildMember.nickname || message.author.username ) + ': ' + errAddRole ); } );
} ).catch( errAddRole => { console.error( ': FAILED to add micro role for ' + ( guildMember.nickname || message.author.username ) + ': ' + errAddRole ); } );
}
}
}
if ( isDebug ) {
if ( message.author.id !== message.client.user.id ) {
console.log( 'Message ID: ' + message.id + ' - author ID: ' + message.author.id + ' -flags- ' + ( message.author.id === message.client.user.id ? '1' : '0' ) + ( isOwner ? '1' : '0' ) + ( isCrown ? '1' : '0' ) + ( isAdmin ? '1' : '0' ) );
console.log( 'Guild#Channel: ' + message.guild.name + '#' + message.channel.name + ' Author: ' + message.author.tag );
console.log( 'Message.content: ' + message.content );
}
}
var command = message.content.replace( / */g, ' ' ).split( ' ' );
var arrArgs = [];
if ( command[ 0 ].match( /<@!?(\d*)>/ ) ) {
if ( command[ 0 ].match( /<@!?(\d*)>/ )[ 1 ] === client.user.id && command.length > 1 ) {
arrArgs = command.slice( 2 );
command = command[ 1 ].toLowerCase();
} else {
arrArgs = command;
command = false;
}
} else if ( command[ 0 ].indexOf( '!' ) === 0 ) {
arrArgs = command.slice( 1 );
command = command[ 0 ].toLowerCase();
} else {
arrArgs = command;
command = false;
}
var strArgs = arrArgs.join( ' ' );
if ( !command ) {
/* Do nothing, it's not my command. */
} else if ( command.substr( 0, 1 ) === '!' ) {
command = command.substr( 1 ).toLowerCase();
}
var strUserName;
if ( command ) {
if ( arrArgs[ 0 ] !== undefined ) {
if ( message.guild ) {
if ( message.guild.members.get( arrArgs[ 0 ].replace( /<@!?/, '' ).replace( />/, '' ) ) !== undefined ) {
let strID = arrArgs[ 0 ].replace( /<@!?/, '' ).replace( />/, '' );
objUser = message.guild.members.get( strID );
strUserName = ( objUser.nickname || objUser.user.username );
} else {
strUserName = arrArgs.join( ' ' );
}
} else {
strUserName = 'greenie';
}
} else if ( message.guild ) {
if ( message.guild.members.get( message.author.id ).nickname !== null ) {
strUserName = message.guild.members.get( message.author.id ).nickname;
} else {
strUserName = message.author.username;
}
} else {
strUserName = message.author.username;
}
} else {
strUserName = 'greenie';
}
if ( message.guild && arrArgs[ 0 ] !== undefined ) {// && !isOwner && !isCrown && !isAdmin
if ( message.guild.id === '192775085420052489' ) {
var DiscordInvites = [ ];
arrArgs.forEach( function( thisArg ) {
var thisInvite = thisArg.trim().replace( /\W_/g, '' );
if ( thisArg.match( /(https?:\/\/)?discord(app)?\.(gg|me)\/(.*?)/i ) !== null ) {
DiscordInvites.push( thisInvite );
}
} );
if ( message.author.id !== client.user.id && DiscordInvites.length >= 1 ) {
var objCrown = await message.client.fetchUser( strCrownID );
console.log( 'Invite(s) Detected: ' + DiscordInvites );
message.delete( { reason: 'Deleting invite posted without permission.' } )
.then( async doneDel => {
console.log( 'Done: ' + doneDel );
await objCrown.send( 'Successfully deleted ' + message.author + '\'s unpermitted guild invite from ' + message.guild.name + '**#**' + message.channel.name + ': `' + DiscordInvites.join( '` - `' ) + '`' );
} ).catch( async errDel => {
console.log( 'Error: ' + errDel );
await objCrown.send( 'Failed to delete ' + message.author + '\'s unpermitted guild invite from ' + message.guild.name + '**#**' + message.channel.name + ': `' + DiscordInvites.join( '` - `' ) + '`' );
} );
}
}
}
if ( arrArgs[ 0 ] !== undefined ) {
var GCcodes = [ ];
var TBcodes = [ ];
arrArgs.forEach( function( thisArg ) {
var thisCode = thisArg.trim().replace( /\W_/g, '' );
if ( thisArg.match( /^GC[A-Z0-9]{2,6}$/i ) !== null ) {
GCcodes.push( thisCode );
}
if ( thisArg.match( /^TB[A-Z0-9]{2,7}$/i ) !== null ) {
TBcodes.push( thisCode );
}
} );
if ( message.author.id !== client.user.id && GCcodes.length >= 1 ) {
var strMessage = 'GC code(s) detected, here are links: ';
var arrDoneCodes = [ ];
GCcodes.forEach( function( GCcode, ndx ) {
arrDoneCodes.push( GCcode.toUpperCase() );
strMessage += '\n\t' + GCcode.toUpperCase() + ' :link: <https://coord.info/' + GCcode.toUpperCase() + '>';
} );
if ( arrDoneCodes.length >= 1 ) {
message.channel.send( strMessage );
}
}
if ( message.author.id !== client.user.id && TBcodes.length >= 1 ) {
var hasDiscordTB = false;
var strMessage = 'TB reference number(s) detected, here are links: ';
var arrDoneCodes = [ ];
TBcodes.forEach( function( TBcode, ndx ) {
arrDoneCodes.push( TBcode.toUpperCase() );
strMessage += '\n\t' + TBcode.toUpperCase() + ' :link: <https://coord.info/' + TBcode.toUpperCase() + '>';
if ( TBcode.toUpperCase() === 'TB8PPBD' ) {
hasDiscordTB = true;
}
} );
if ( arrDoneCodes.length >= 1 ) {
message.channel.send( strMessage ).then( msgSent => {
if ( hasDiscordTB ) {
msgSent.react( '💚' );
}
} );
}
}
}
if ( isDebug ) {
console.log( 'Attempting to react to command: ' + command );
}
switch ( command ) {
case 'dv' : case 'dver' :
if ( isOwner ) {
message.reply( 'I\'m running Discord.js v'+ Discord.version + ' ? <https://discord.js.org/#/docs/main/' + Discord.version + '/general/welcome>' );
message.delete().catch( errDel => { console.error( '%o: Unable to delete !%s request by %s: %o', strNow(), command, message.author.tag, errDel ); } );
}
break;
case 'about' :
const strOrdinalEmoji = [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'keycap_ten' ];// basic 0-9 and then "10"
var response = await message.channel.send( 'Collecting data for your query, please stand by...' );
try {
var arrMyRoles = message.guild.members.get( message.client.user.id )._roles,
dateJoinedTimestamp = new Date( message.guild.members.get( message.client.user.id ).joinedTimestamp ),
intGuildsList = 0,
intGuilds = 0,
intGuildIndex = 0,
intTopIndex = 0,
intUsers = message.guild.memberCount,
intHumans = 0,
intBots = 0,
intChannels = message.guild.channels.size,
intTextChannels = 0,
intVoiceChannels = 0,
intRoles = message.guild.roles.size,
strBotType = '',
strDebugServer = '',
strInviteMe = '',
strOwner = '',
strLastRestart = '',
strGuildsName = '',
strGuildsValue = '',
strTopIndex = '',
strMyRoles = '',
strCurrentGuildValue = '',
strJoinedTimestamp = dateJoinedTimestamp.toLocaleDateString( 'en-US', objTimeString ),
strCurrentGuildName = message.guild.name;
var objUptime = { base: Math.floor( message.client.uptime / 1000 ) };
objUptime.seconds = ( objUptime.base % 60 );
objUptime.minutes = ( Math.floor( objUptime.base / 60 ) % 60 );
objUptime.hours = ( Math.floor( objUptime.base / 3600 ) % 24 );
objUptime.days = ( Math.floor( objUptime.base / 86400 ) % 7 );
objUptime.weeks = ( Math.floor( objUptime.base / 604800 ) % 4 );
if ( !message.guild.large ) {
await message.guild.members.forEach( function( member, intMemberIndex ) {
if ( member.user.bot ){
intBots++;
} else {
intHumans++;
}
} );
} else {// HORRIBLE HACK -- FIX THIS LATER
await message.guild.members.forEach( function( member, intMemberIndex ) {
if ( member.user.bot ){
intBots++;
}
} );
intHumans = message.guild.memberCount - intBots;
}
Promise.all( [
strBotType = 'In case you didn\'t know, I\'m a ' +
( message.client.user.bot ? ':robot: robot' : ':bust_in_silhouette: human' ) + '.\n',
strDebugServer = 'You can track changes to the bot in my [debugging server](<https://discord.me/TheShoeStore>).\n',
strInviteMe = 'You can add me to your own server(s): [Invite Me!](https://discordapp.com/api/oauth2/authorize?client_id=' + settings[ bot ].clientID + '&scope=bot&permissions=8)\n',
strOwner = 'My owner' + ( settings[ bot ].owners.length === 1 ? ' is ' : 's are ' ),
await settings[ bot ].owners.forEach( async function( ownerID, i ){
var owner = await message.client.fetchUser( ownerID );
strOwner += owner + ' (' + owner.tag + ')';
if ( settings[ bot ].owners.length > 2 && i < settings[ bot ].owners.length ) {