This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathkweh-bot.js
1381 lines (1141 loc) · 48.4 KB
/
kweh-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
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
/******************************
References
*******************************
// https://xivapi.com/docs
// https://universalis.app/docs
// https://ffxivcollect.com/
// https://discord.js.org/#/docs/main/stable/general/welcome
/******************************
Prod / Dev
*******************************/
const config = require('./config').production;
/******************************
Variables & Libs
*******************************/
const { setIntervalAsync } = require('set-interval-async/dynamic')
const { clearIntervalAsync } = require('set-interval-async')
const lodash = require('lodash');
const moment = require("moment");
const Discord = require("discord.js");
const scriptName = __filename.slice(__dirname.length + 1);
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Discord.Intents.FLAGS.GUILD_MESSAGE_TYPING
],
makeCache: Discord.Options.cacheWithLimits({
MessageManager: 10,
PresenceManager: 0,
}),
sweepers: {
messages: {
lifetime: 1800,
interval: 3600
}
}
});
const pool = config.getPool();
const readPool = config.getReadPool()
const redis = config.getRedis();
let fashionCheckIntervals = 600 * 1000;
let lodestoneCheckIntervals = 600 * 1000;
let kwehNewsCheckIntervals = 600 * 1000;
/******************************
Bot Auth
*******************************/
if( scriptName == 'dev-bot.js' ) {
client.login(config.devBotToken);
config.botID = config.devBotID;
console.log("----- DEVELOPMENT BOT -----");
}
else {
client.login(config.discordBotToken);
console.log("----- PRODUCTION BOT -----");
}
// Modules
const helper = require("./helper.js");
const dcserver = require("./modules/dcserver.js");
const tripletriad = require("./modules/tripletriad.js");
const fflogs = require("./modules/fflogs.js");
const lodestone_news = require("./modules/lodestone_news.js");
const kweh_news = require("./modules/kweh_news.js");
const fashion_report = require("./modules/fashion_report.js");
const eorzea_time = require("./modules/eorzea_time.js");
const eorzea_collection = require("./modules/eorzea_collection.js");
const xivcollect = require("./modules/xivcollect.js");
const housing_snap = require("./modules/housing_snap.js");
let character, marketboard, item;
/******************************
Event Listeners
*******************************/
client.on("error", (e) => console.error(e));
client.on("warn", (e) => console.warn(e));
client.on("ready", async function() {
helper.printStatus(config.appName + " bot is ready!");
client.user.setPresence({ activities: [{ name: '@kweh help', type: "PLAYING"}], status: 'online'});
// Check Lodestone periodically
setIntervalAsync(lodestone_news.autoCheckPostNews, lodestoneCheckIntervals, client);
// Check fashion report periodically
setIntervalAsync(fashion_report.autoCheckPostFR, fashionCheckIntervals, client);
// Check kweh news periodically
setIntervalAsync(kweh_news.autoCheckPostNews, kwehNewsCheckIntervals, client);
});
/******************************
Reaction Listener
*******************************/
client.on('messageReactionAdd', async function(reaction, user) {
if ( user.bot ) return; // Ignore bots
if( reaction.message.author.id == config.botID ) { // only process kweh messages
if( reaction.message.embeds.length > 0 ) {
// Eorzea Collection
if( reaction.message.embeds[0].hasOwnProperty('author') && reaction.message.embeds[0].author.hasOwnProperty('name') && reaction.message.embeds[0].author.name.includes("Eorzea Collection") ) {
let numberOptions = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'];
if(reaction.emoji.name === "⬅️") {
await eorzea_collection.loadNextImg(reaction, "desc");
}
if(reaction.emoji.name === "➡️") {
await eorzea_collection.loadNextImg(reaction, "asc");
}
if(numberOptions.includes(reaction.emoji.name)) {
await eorzea_collection.loadGlamNo(reaction, reaction.emoji.name);
}
}
// Housing Snap
if( reaction.message.embeds[0].hasOwnProperty('author') && reaction.message.embeds[0].author.hasOwnProperty('name') && reaction.message.embeds[0].author.name.includes("Housing Snap") ) {
let numberOptions = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'];
if(reaction.emoji.name === "⬅️") {
await housing_snap.loadNextImg(reaction, "desc");
}
if(reaction.emoji.name === "➡️") {
await housing_snap.loadNextImg(reaction, "asc");
}
if(numberOptions.includes(reaction.emoji.name)) {
await housing_snap.loadItemNo(reaction, reaction.emoji.name);
}
}
}
}
});
/******************************
Message Listener
*******************************/
client.on("messageCreate", async function(message) {
if ( message.author.bot ) return; // Ignore bots
if ( !message.channel.guild ) return; // Ignore dm
// Work-around for message intent removal
// Must have @bot in message
message.content = message.content.replace('<@'+config.botID+'>', '')
// Remove bot from mentioned used collection
message.mentions.users = message.mentions.users.filter(user => user.id != config.botID);
if ( message.content === '' ) return; // Ignore empty messages
const args = message.content.trim().split(/ +/g).map(args => args.toLowerCase());
const command = args.shift().toLowerCase();
if( config.commands.includes(command) == false ) return; // Ignore commands not in "commands" array
const serverSettings = await getServerSettings(message.guild.id, client);
const language = serverSettings["language"];
const default_channel_id = serverSettings["default_channel_id"];
const default_channel = serverSettings["default_channel"];
let auto_delete = serverSettings["auto_delete"];
const isAdmin = helper.isAdmin(message.member);
const isSuperAdmin = helper.isSuperAdmin(message.member);
message.serverSettings = serverSettings;
message.logCommandID = await helper.logCommands(message, isAdmin, true);
message.client = client;
message.response_channel = default_channel ? default_channel : message.channel;
updateServerInfo(message.guild.id, message.guild.name);
// Throttle Check
let msgThrottleCheck = await throttleCheck(message.guild.id);
if( msgThrottleCheck == false ) {
helper.sendErrorMsg("Slow down!", "Too many commands received in the last 5s.", message);
return;
}
/***********************************
**** LOCALIZATIONS
************************************/
if( language == "jp" ) {
item = require("./modules/jp/item.js");
character = require("./modules/jp/character.js");
marketboard = require("./modules/jp/marketboard.js");
}
else if( language == "fr" ) {
item = require("./modules/fr/item.js");
character = require("./modules/fr/character.js");
marketboard = require("./modules/marketboard.js");
}
else if( language == "de" ) {
item = require("./modules/de/item.js");
character = require("./modules/de/character.js");
marketboard = require("./modules/marketboard.js");
}
else {
item = require("./modules/item.js");
character = require("./modules/character.js");
marketboard = require("./modules/marketboard.js");
}
/*******************************************
**** SERVER SETTINGS
**** LANGUAGE / AUTODELETE / DEFAULT CHANNEL
********************************************/
if ( command === "language" ) {
if( args.length == 0 ) {
helper.sendInfoMsg("Info", "The server's language is `" + language + "`", message);
}
else {
if( isAdmin ) {
if( config.languageOptions.includes(args[0]) ) {
setServerLanguage(message.guild.id, args[0]);
helper.sendSuccessMsg("Success", "The server's language is now: `" + args[0]+"`", message);
}
else {
helper.sendErrorMsg("Error", "Changing server's language to `" + args[0] + "` failed. \nValid options are `" + config.languageOptions.join(", ") + "`", message);
}
}
else {
helper.sendErrorMsg("Error", "Only admins are allowed to change server settings", message);
}
}
}
else if( command === 'autodelete' ) {
if( args.length == 0 ) {
if( auto_delete ) {
helper.sendInfoMsg("Info", "Auto deletion of commands is enabled. \n\nDisable it with `@kweh autodelete off`", message);
}
else {
helper.sendInfoMsg("Info", "Auto deletion of commands is disabled. \n\nEnable it with `@kweh autodelete on`", message);
}
}
else {
if( isAdmin ) {
if( args[0] == 'on' ) {
enableAutoDelete(message.guild.id);
auto_delete = true;
helper.sendSuccessMsg("Success", "Auto deletion is enabled.", message);
}
else if( args[0] == 'off' ) {
disableAutoDelete(message.guild.id);
auto_delete = false;
helper.sendSuccessMsg("Success", "Auto deletion is disabled.", message);
}
else {
if( auto_delete ) {
helper.sendInfoMsg("Info", "Auto deletion of commands is enabled. \n\nDisable it with `@kweh autodelete off`", message);
}
else {
helper.sendInfoMsg("Info", "Auto deletion of commands is disabled. \n\nEnable it with `@kweh autodelete on`", message);
}
}
}
else {
helper.sendErrorMsg("Error", "Only admins are allowed to change server settings", message);
}
}
}
else if( command == 'channel' ) {
if( args.length == 0 ) {
if( default_channel ) {
helper.sendInfoMsg("Info", "The default channel for " + config.appName + " is #" + default_channel.name, message);
}
else {
helper.sendInfoMsg("Info", "No default bot response channel has been set. \n\nForce all bot messages to be sent to a specific channel with \n`@kweh channel #your-channel-name`", message);
}
}
else {
if( isAdmin ) {
// Set channel
let targetChannel = message.mentions.channels.first();
if( targetChannel && args[0] != 'remove' && args[0] != 'rm' ) {
await setDefaultChannel(message.guild.id, targetChannel.id);
helper.sendSuccessMsg("Success", "The default response channel for " + config.appName + " bot has been set to #" + targetChannel.name, message);
}
else {
// Remove channel
if( args[0] == 'remove' || args[0] == 'rm' ) {
if( default_channel ) {
removeDefaultChannel(message.guild.id);
helper.sendInfoMsg("Info", "The default response channel #" + default_channel.name + " has been removed.", message, true);
}
else {
helper.sendInfoMsg("Info", "No default bot response channel has been set. \n\nForce all bot messages to be sent to a specific channel with \n`@kweh channel #your-channel-name`", message);
}
}
else {
helper.sendInfoMsg("Info", "No default bot response channel has been set. \n\nForce all bot messages to be sent to a specific channel with \n`@kweh channel #your-channel-name`", message);
}
}
}
else {
helper.sendErrorMsg("Error", "Only admins are allowed to change server settings", message);
}
}
}
/*************************************************
**** PING
*************************************************/
else if ( command === "ping" ) {
client.shard.fetchClientValues('guilds.cache.size')
.then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
.catch(console.error);
const message_timestamp = message.createdTimestamp;
const curr_timestamp = Date.now();
const pong_time = curr_timestamp - message_timestamp;
message.response_channel.send("Pong in " +pong_time+ " ms" + " on shard " + message.guild.shardId);
}
/*************************************************
**** REGISTER CHARACTER
*************************************************/
else if ( command === "register" || command === "iam" ) {
helper.doTyping(message.response_channel);
// server, firstname, lastname
if( args.length == 3 ) {
let server = args[0];
let firstname = args[1];
let lastname = args[2];
let isValidServer = await dcserver.isServer(server);
if( isValidServer == false ) {
helper.sendErrorMsg("Error", "Invalid server `"+server+"`", message);
}
else {
let characterSearchResult = {}
// todo: uncomment when fixed
// characterSearchResult = await character.searchCharacter(server, firstname, lastname);
if( lodash.isEmpty(characterSearchResult) ) {
characterSearchResult = await character.searchCharacterOwnServer(server, firstname, lastname);
}
if( lodash.isEmpty(characterSearchResult) == false ) {
let characterInfo = await character.getCharacterInfoOwnServer(characterSearchResult, language);
let region = dcserver.getDCregion(characterInfo.datacenter);
characterInfo.discordID = message.author.id;
if( lodash.isEmpty(characterInfo) == false ) {
character.printCharacterInfo(characterInfo, message);
}
// Update Profile
character.setUserInfo(message.author.id, characterInfo.datacenter, characterInfo.server, region, characterSearchResult.firstname, characterSearchResult.lastname, characterSearchResult.lodestone_id);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
}
// lodestone id
else if( args.length == 1 ) {
let lodestone_id = args[0];
let characterSearchResult = {
'lodestone_id': lodestone_id
};
let characterInfo = await character.getCharacterInfoOwnServer(characterSearchResult, language);
if( lodash.isEmpty(characterInfo) == false ) {
let region = dcserver.getDCregion(characterInfo.datacenter);
characterInfo.discordID = message.author.id;
character.printCharacterInfo(characterInfo, message);
characterSearchResultNameArr = characterInfo.name.split(" ");
characterSearchResult.firstname = characterSearchResultNameArr[0];
characterSearchResult.lastname = characterSearchResultNameArr[1];
// Update Profile
character.setUserInfo(message.author.id, characterInfo.datacenter, characterInfo.server, region, characterSearchResult.firstname, characterSearchResult.lastname, characterSearchResult.lodestone_id);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Register your character with \n`@kweh "+command+" server firstname lastname`", message);
}
}
/*************************************************
**** GET CHARACTER
*************************************************/
else if ( command === "me" || command === "whoami" ) {
helper.doTyping(message.response_channel);
let userInfo = await character.getUserInfo(message.author.id);
if( lodash.isEmpty(userInfo) == false ) {
let characterInfo = await character.getCharacterInfoOwnServer(userInfo, language); // await character.getCharacterInfo(userInfo);
if( lodash.isEmpty(characterInfo) == false ) {
characterInfo.discordID = message.author.id;
character.printCharacterInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Profile not found. \n\nRegister your character with \n`@kweh register server firstname lastname`", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found. \n\nRegister your character with \n`@kweh register server firstname lastname`", message);
}
}
/*************************************************
**** GET CHARACTER OF TARGET / MENTIONED
*************************************************/
else if ( command === "whois" || command === "profile" ) {
helper.doTyping(message.response_channel);
// Self
if( args.length == 0 ) {
let userInfo = await character.getUserInfo(message.author.id);
if( lodash.isEmpty(userInfo) == false ) {
let characterInfo = await character.getCharacterInfoOwnServer(userInfo, language);
if( characterInfo ) {
characterInfo.discordID = message.author.id;
character.printCharacterInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
// Specific User
else if( args.length == 3 ) {
let server = args[0];
let firstname = args[1];
let lastname = args[2];
let isValidServer = await dcserver.isServer(server);
if( isValidServer == false ) {
helper.sendErrorMsg("Error", "Invalid server `"+server+"`", message);
}
else {
let characterSearchResult = {}
// todo: uncomment when fixed
// characterSearchResult = await character.searchCharacter(server, firstname, lastname);
if( lodash.isEmpty(characterSearchResult) ) {
characterSearchResult = await character.searchCharacterOwnServer(server, firstname, lastname);
}
if( lodash.isEmpty(characterSearchResult) == false ) {
let characterInfo = await character.getCharacterInfoOwnServer(characterSearchResult, language);
if( lodash.isEmpty(characterInfo) == false ) {
character.printCharacterInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
}
// Mentioned User
else if( args.length > 0 ) {
if( message.mentions.users.first() ) {
let userInfo = await character.getUserInfo(message.mentions.users.first().id);
if( lodash.isEmpty(userInfo) == false ) {
let characterInfo = await character.getCharacterInfoOwnServer(userInfo, language);
if( lodash.isEmpty(characterInfo) == false ) {
characterInfo.discordID = message.mentions.users.first().id;
character.printCharacterInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
// By Lodestone ID
else if(args.length == 1) {
let lodestone_id = args[0];
let characterSearchResult = {
'lodestone_id': lodestone_id
};
let characterInfo = await character.getCharacterInfoOwnServer(characterSearchResult, language);
if( lodash.isEmpty(characterInfo) == false ) {
character.printCharacterInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "View character profile with \n`@kweh "+command+" server firstname lastname`", message);
}
}
}
/*************************************************
**** GET GLAMS OF TARGET / MENTIONED
*************************************************/
else if ( command === "glam" || command === "glamour" ) {
helper.doTyping(message.response_channel);
// Self
if( args.length == 0 ) {
let userInfo = await character.getUserInfo(message.author.id);
if( lodash.isEmpty(userInfo) == false ) {
let characterInfo = await character.getCharacterInfoXIVAPI(userInfo, false);
if( characterInfo ) {
character.printGlamInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
// Specific User
else if( args.length == 3 ) {
let server = args[0];
let firstname = args[1];
let lastname = args[2];
let isValidServer = await dcserver.isServer(server);
if( isValidServer == false ) {
helper.sendErrorMsg("Error", "Invalid server `"+server+"`", message);
}
else {
let characterSearchResult = {}
// todo: uncomment when fixed
// characterSearchResult = await character.searchCharacter(server, firstname, lastname);
if( lodash.isEmpty(characterSearchResult) ) {
characterSearchResult = await character.searchCharacterOwnServer(server, firstname, lastname);
}
if( lodash.isEmpty(characterSearchResult) == false ) {
let characterInfo = await character.getCharacterInfoXIVAPI(characterSearchResult, false);
if( lodash.isEmpty(characterInfo) == false ) {
character.printGlamInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
}
// Mentioned User
else if( args.length > 0 ) {
if( message.mentions.users.first() ) {
let userInfo = await character.getUserInfo(message.mentions.users.first().id);
if( lodash.isEmpty(userInfo) == false ) {
let characterInfo = await character.getCharacterInfoXIVAPI(userInfo, false);
if( lodash.isEmpty(characterInfo) == false ) {
characterInfo.discordID = message.mentions.users.first().id;
character.printGlamInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
else if(args.length == 1) {
let lodestone_id = args[0];
let characterSearchResult = {
'lodestone_id': lodestone_id
};
let characterInfo = await character.getCharacterInfoXIVAPI(characterSearchResult, false);
if( lodash.isEmpty(characterInfo) == false ) {
character.printGlamInfo(characterInfo, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "View character glamours with \n`@kweh "+command+" server firstname lastname`", message);
}
}
}
/*************************************************
**** GET FFLOGS FOR CHARACTER
*************************************************/
else if ( command === "logs" || command === "fflogs" || command === "parses" ) {
helper.doTyping(message.response_channel);
// Self
if( args.length == 0 ) {
let userInfo = await character.getUserInfo(message.author.id);
if( lodash.isEmpty(userInfo) == false ) {
let name = userInfo.firstname + " " + userInfo.lastname;
let logsResults = await fflogs.getFFLogsGQL(name, userInfo.server, userInfo.region);
fflogs.printFFLogsGQL(logsResults, message);
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
// Specific User
else if( args.length == 3 ) {
let server = args[0];
let firstname = args[1];
let lastname = args[2];
let isValidServer = await dcserver.isServer(server);
if( isValidServer == false ) {
helper.sendErrorMsg("Error", "Invalid server `"+server+"`", message);
}
else {
let characterSearchResult = {}
// uncomment when fixed
// characterSearchResult = await character.searchCharacter(server, firstname, lastname);
if( lodash.isEmpty(characterSearchResult) ) {
characterSearchResult = await character.searchCharacterOwnServer(server, firstname, lastname);
}
if( lodash.isEmpty(characterSearchResult) == false ) {
let characterInfo = await character.getCharacterInfoOwnServer(characterSearchResult, language);
if( lodash.isEmpty(characterInfo) == false ) {
let name = firstname + " " + lastname;
let region = dcserver.getDCregion(characterInfo.datacenter);
let logsResults = await fflogs.getFFLogsGQL(name, characterInfo.server, region);
fflogs.printFFLogsGQL(logsResults, message);
}
else {
helper.sendErrorMsg("Error", "Character not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
}
// Mentioned User
else if( args.length > 0 ) {
if( message.mentions.users.first() ) {
let userInfo = await character.getUserInfo(message.mentions.users.first().id);
if( lodash.isEmpty(userInfo) == false ) {
let name = userInfo.firstname + " " + userInfo.lastname;
let logsResults = await fflogs.getFFLogsGQL(name, userInfo.server, userInfo.region);
fflogs.printFFLogsGQL(logsResults, message);
}
else {
helper.sendErrorMsg("Error", "Profile not found", message);
}
}
else {
helper.sendErrorMsg("Error", "View FFLogs with \n`@kweh "+command+" server firstname lastname`", message);
}
}
}
/*************************************************
**** Market Board Search
*************************************************/
else if ( command === "mb" || command === "market" || command == "marketboard" ) {
helper.doTyping(message.response_channel);
// dc + item name
if( args.length > 0 ) {
let dcOrServerOrRegion = args[0];
let searchedItem = args.slice(1).join(' ');
let isDCSupplied = await dcserver.isDC(dcOrServerOrRegion);
let isServerSupplied = await dcserver.isServer(dcOrServerOrRegion);
let isRegionSupplied = dcserver.isRegion(dcOrServerOrRegion);
// Try to get DC from user profile if not specified
if( !isRegionSupplied && !isServerSupplied && !isDCSupplied ) {
let userInfo = await character.getUserInfo(message.author.id);
if( lodash.isEmpty(userInfo) == false ) {
dcOrServerOrRegion = userInfo.dc;
isDCSupplied = true;
// overwrite with region
/*
if( dcserver.isRegion(userInfo.region) ) {
dcOrServerOrRegion = userInfo.region;
isDCSupplied = false;
isRegionSupplied = true;
}
*/
searchedItem = args.join(' ');
}
}
if( isRegionSupplied || isDCSupplied || isServerSupplied ) {
let itemMatchResult = await item.searchItemByName(searchedItem);
if( itemMatchResult.length == 0 ) {
helper.sendErrorMsg("Error", "Item "+searchedItem+" not found", message);
}
else if( itemMatchResult.length == 1 ) {
let itemInfo = itemMatchResult[0];
await marketboard.printMarketboardResult(itemInfo, dcOrServerOrRegion, isDCSupplied, isRegionSupplied, message);
}
else if( itemMatchResult.length > 1 ) {
await marketboard.handleMultipleItems(itemMatchResult, searchedItem, dcOrServerOrRegion, isDCSupplied, isRegionSupplied, message);
}
}
else {
helper.sendErrorMsg("Error", "Invalid region, datacenter or server", message);
}
}
else {
helper.sendErrorMsg("Error", "Lookup marketboard prices with \n`@kweh "+command+" datacenter/server itemname`", message);
}
}
/*************************************************
**** ITEM SEARCH
*************************************************/
else if ( command === "item" ) {
helper.doTyping(message.response_channel);
if( args.length > 0 ) {
let searchedItem = args.join(' ');
let itemMatchResult = await item.searchItemByName(searchedItem);
if( itemMatchResult.length == 0 ) {
helper.sendErrorMsg("Error", "Item "+searchedItem+" not found", message);
}
else if( itemMatchResult.length == 1 ) {
let specificItemInfo = await item.getItemByID( itemMatchResult[0].ID );
// print result
item.displayItem(specificItemInfo, message);
}
else if( itemMatchResult.length > 1 ) {
await item.handleMultipleItems(itemMatchResult, searchedItem, message);
}
}
else {
helper.sendErrorMsg("Error", "Lookup items with \n`@kweh "+command+" itemname`", message);
}
}
/*************************************************
**** MOUNT SEARCH ON XIVCOLLECT
*************************************************/
else if ( command === "mount" ) {
helper.doTyping(message.response_channel);
if( args.length > 0 ) {
let searchedItem = args.join(' ');
let itemMatchResult = await xivcollect.getMountData(message, searchedItem);
if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length == 1 ) {
await xivcollect.printItemInfo(itemMatchResult.results[0], message);
}
else if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length > 1 ) {
await xivcollect.handleMultipleItems(itemMatchResult, searchedItem, message);
}
else {
helper.sendErrorMsg("Error", "Mount "+searchedItem+" not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Lookup mounts with \n`@kweh "+command+" search_string`", message);
}
}
/*************************************************
**** MINION SEARCH ON XIVCOLLECT
*************************************************/
else if ( command === "minion" ) {
helper.doTyping(message.response_channel);
if( args.length > 0 ) {
let searchedItem = args.join(' ');
let itemMatchResult = await xivcollect.getMinionData(message, searchedItem);
if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length == 1 ) {
await xivcollect.printItemInfo(itemMatchResult.results[0], message);
}
else if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length > 1 ) {
await xivcollect.handleMultipleItems(itemMatchResult, searchedItem, message);
}
else {
helper.sendErrorMsg("Error", "Minion "+searchedItem+" not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Lookup minions with \n`@kweh "+command+" search_string`", message);
}
}
/*************************************************
**** TITLE SEARCH ON XIVCOLLECT
*************************************************/
else if ( command === "title" ) {
helper.doTyping(message.response_channel);
if( args.length > 0 ) {
let searchedItem = args.join(' ');
let itemMatchResult = await xivcollect.getTitleData(message, searchedItem);
if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length == 1 ) {
await xivcollect.printItemInfo(itemMatchResult.results[0], message);
}
else if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length > 1 ) {
await xivcollect.handleMultipleItems(itemMatchResult, searchedItem, message);
}
else {
helper.sendErrorMsg("Error", "Title "+searchedItem+" not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Lookup titles with \n`@kweh "+command+" search_string`", message);
}
}
/*************************************************
**** EMOTE SEARCH ON XIVCOLLECT
*************************************************/
else if ( command === "emote" ) {
helper.doTyping(message.response_channel);
if( args.length > 0 ) {
let searchedItem = args.join(' ');
let itemMatchResult = await xivcollect.getEmoteData(message, searchedItem);
if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length == 1 ) {
await xivcollect.printItemInfo(itemMatchResult.results[0], message);
}
else if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length > 1 ) {
await xivcollect.handleMultipleItems(itemMatchResult, searchedItem, message);
}
else {
helper.sendErrorMsg("Error", "Emote "+searchedItem+" not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Lookup emotes with \n`@kweh "+command+" search_string`", message);
}
}
/*************************************************
**** BARDING SEARCH ON XIVCOLLECT
*************************************************/
else if ( command === "barding" ) {
helper.doTyping(message.response_channel);
if( args.length > 0 ) {
let searchedItem = args.join(' ');
let itemMatchResult = await xivcollect.getBardingData(message, searchedItem);
if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length == 1 ) {
await xivcollect.printItemInfo(itemMatchResult.results[0], message);
}
else if( lodash.isEmpty(itemMatchResult) == false && itemMatchResult.results.length > 1 ) {
await xivcollect.handleMultipleItems(itemMatchResult, searchedItem, message);
}
else {
helper.sendErrorMsg("Error", "Barding "+searchedItem+" not found", message);
}
}
else {
helper.sendErrorMsg("Error", "Lookup bardings with \n`@kweh "+command+" search_string`", message);
}
}
/*************************************************
**** GET TRIPLE TRIAD FOR CHARACTER
*************************************************/
else if ( command === "tt" || command === "ttcollection" || command === "cards" ) {
helper.doTyping(message.response_channel);
if( args.length == 0 ) {
let tripleTriadData = await tripletriad.getFFTripleTriadData(message.author.id);
if( lodash.isEmpty(tripleTriadData) == false ) {
tripletriad.printTripleTriadData(tripleTriadData, message, message.author);
}
else {
helper.sendErrorMsg("Error", "Triple triad profile not found\nRegister at [https://triad.raelys.com](https://triad.raelys.com)", message);
}
}
// Mentioned User
else if( args.length > 0 ) {
if( message.mentions.users.first() ) {
let tripleTriadData = await tripletriad.getFFTripleTriadData(message.mentions.users.first().id);
if( lodash.isEmpty(tripleTriadData) == false ) {
tripletriad.printTripleTriadData(tripleTriadData, message, message.mentions.users.first());
}
else {
helper.sendErrorMsg("Error", "Triple triad profile not found for <@" + message.mentions.users.first().id + ">", message);
}
}
}
}
/*************************************************
**** KWEH NEWS NOTIFICATIONS
*************************************************/
else if ( command === "kweh_news" ) {
if( isAdmin ) {
if( helper.isSuperAdmin(message.author) ) {
kweh_news.autoCheckPostNews(client);
}