-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcbot.js
1706 lines (1488 loc) · 64.7 KB
/
dcbot.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
// Require the necessary discord.js classes
const { Client, GatewayIntentBits, ModalBuilder, TextInputBuilder, TextInputStyle, codeBlock } = require('discord.js');
const { clientId, token } = require('./config.json');
const { REST, Routes, SelectMenuBuilder } = require('discord.js');
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } = require('discord.js');
console.log('rrrrrrrrrrrrrrr')
const XMLHttpRequest = require('xhr2');
const fs = require('node:fs');
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
var mysql = require('mysql2');
const { resolve } = require('node:path');
const { reject } = require('ramda');
var con = mysql.createConnection({
host: "ls-25e48440f1e5122125b59df1847a9c9c7d06e1c0.cagodxgzv1qf.eu-central-1.rds.amazonaws.com",
user: "dbmasteruser",
password: "",
port: "3306",
database: "defaultdb"
});
// Create a new client instance And add commands
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages
, GatewayIntentBits.MessageContent] });
client.once('ready', async () => {
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
console.log('Ready!');
});
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
(async () => {
try {
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
} catch (error) {
console.error(error);
}
})();
// ************************************************************ //
client.on('interactionCreate', async interaction => {
let member = interaction.guild.members.cache.get(interaction.user.id)
let hasRole = member.roles.cache.some(role => role.name === 'RZ Boss')
if (interaction.isCommand()){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
if (interaction.commandName === 'dashboard') {
if(hasRole)
{
var sql = "SELECT * from rr_subs where dc_id = '" + interaction.guild.id + "';";
isWhitelisted = false;
con.query(sql, async (err, result) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
if(result.length != 0){
if(result[0].consumed <= result[0].quota){
isWhitelisted = true
try{
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('createbtn')
.setLabel('Create RR')
.setStyle(ButtonStyle.Primary),
).addComponents(
new ButtonBuilder()
.setCustomId('addmissionbtn')
.setLabel('Add Mission')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
.setCustomId('rrdetailsbtn')
.setLabel('RR Details')
.setStyle(ButtonStyle.Secondary),
).addComponents(
new ButtonBuilder()
.setCustomId('rrleaderboardbtn')
.setLabel('RR Leaderboard')
.setStyle(ButtonStyle.Success),
);
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle(client.guilds.cache.get(interaction.guild.id).name + ' Dashboard')
.setDescription('RevengerZ helps you manage and organise raiding contests, with a new concept called Raiding Runs')
embed1.addFields({ name: 'Create RR', value: codeBlock('yaml', "Create a new Raiding Run") , inline: false })
embed1.addFields({ name: 'RR Details', value: codeBlock('yaml',"Get Your RR Details"), inline: false })
embed1.addFields({ name: 'RR Leaderboard', value: codeBlock('yaml',"Get The Leaderboard of a Specific RR"), inline: false })
await interactionReply(embed1, interaction, row);
})
}catch(err){
console.log(err)
sendErrorEmbed(interaction);
}
}else{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle(client.guilds.cache.get(interaction.guild.id).name + ' Dashboard')
.setDescription('Sorry, but either you are not subscribed or your subscription has expied!')
await interactionReply(embed1, interaction, null);
})
}
}else{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle(client.guilds.cache.get(interaction.guild.id).name + ' Dashboard')
.setDescription('Sorry, but either you are not subscribed or your subscription has expied!')
await interactionReply(embed1, interaction, null);
})
}
}
})
}
else{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle(client.guilds.cache.get(interaction.guild.id).name + ' Dashboard')
embed1.setDescription('You haven\'t "*RZ Boss*" role')
await interactionReply(embed1, interaction, null);
})
}
}
}
else if (interaction.isButton()) {
console.log(' ------------------- ')
if(interaction.customId === 'createbtn')
{
console.log(' oooooooooooooooooooo ')
const modal = new ModalBuilder()
.setCustomId('createrrmodal')
.setTitle('Create New RR');
const tokenaddress = new TextInputBuilder()
.setCustomId('rrnameinput')
.setLabel("RR Title")
.setStyle(TextInputStyle.Short);
const tokenname = new TextInputBuilder()
.setCustomId('rrrewardinput')
.setLabel("Reward")
.setStyle(TextInputStyle.Short);
const claimrate = new TextInputBuilder()
.setCustomId('nbpointsinput')
.setLabel("Total Points Target")
.setStyle(TextInputStyle.Short);
const tokenaddressRow = new ActionRowBuilder().addComponents(tokenaddress);
const tokennameRow = new ActionRowBuilder().addComponents(tokenname);
const claimrateRow = new ActionRowBuilder().addComponents(claimrate);
// Add inputs to the modal
modal.addComponents(tokenaddressRow, tokennameRow, claimrateRow);
// Show the modal to the user
await interaction.showModal(modal);
}
else if(interaction.customId === 'rrdetailsbtn') {
const modal = new ModalBuilder()
.setCustomId('rrdetailsmodal')
.setTitle('Get RR Details');
const tokenaddress = new TextInputBuilder()
.setCustomId('rrnameinput')
.setLabel("RR Title")
.setStyle(TextInputStyle.Short);
const tokenaddressRow = new ActionRowBuilder().addComponents(tokenaddress);
// Add inputs to the modal
modal.addComponents(tokenaddressRow);
// Show the modal to the user
await interaction.showModal(modal);
}else if(interaction.customId === 'rrleaderboardbtn'){
const modal = new ModalBuilder()
.setCustomId('rrleaderboardmodal')
.setTitle('Get RR Details');
const tokenaddress = new TextInputBuilder()
.setCustomId('rrnameinput')
.setLabel("RR Title")
.setStyle(TextInputStyle.Short);
const tokenaddressRow = new ActionRowBuilder().addComponents(tokenaddress);
// Add inputs to the modal
modal.addComponents(tokenaddressRow);
// Show the modal to the user
await interaction.showModal(modal);
}else if(interaction.customId === 'addmissionbtn'){
const choices = new SelectMenuBuilder()
.setCustomId('missiontype')
.setPlaceholder('Select mission type')
choices.addOptions({
label: 'Option 1',
description: "Raid 2 Earn",
value: 'r2e',
})
choices.addOptions({
label: 'Option 2',
description: "Tweet 2 Earn",
value: 't2e',
})
const row = new ActionRowBuilder()
.addComponents(
choices
);
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
await interaction.reply({ ephemeral: true, embeds: [embed1], components: [row]})
})
}else if(interaction.customId === 'registerbtn'){
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Register Now!')
.setURL("https://revengerz.xyz")
.setStyle(ButtonStyle.Link))
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('How to Register ?')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/5836/5836184.png')
.setDescription('1- Head to https://revengerz.xyz\n'+
'2- Connect you wallet\n'+
'3- Go to your profile\n'+
'4- Link your discord and twitter accounts')
await interactionReply(embed1, interaction, row);
})
}else if(interaction.customId === 'leaderboardbtn'){
var sql = "SELECT * from raiding_run where rr_name = '" + interaction.message.embeds[0].fields[0].value +"' and dc_id = '" + interaction.guild.id + "';";
con.query(sql, async (err, result) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
var sql = "SELECT * from raiding_run_user where rr_id = '" + result[0].rr_id +"' and dc_id = '" + interaction.guild.id + "' ORDER BY points DESC;";
con.query(sql, async (err, result2) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
try{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('RR Leaderboard')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/548/548481.png')
const boo = new Promise((resolve, reject) => {
if(result2.length == 0)
resolve(true)
result2.forEach((x, i, array) => {
if(i <= 9)
embed1.addFields({ name: 'Place N°'+ parseInt(i+1), value: "**" + x.username + "**" + " (*id: " + x.user_id + "*, **" + x.points + " Points** )" , inline: false })
if(i == array.length - 1 || i == 9) {
resolve(true)
}
})
})
boo.then(async () => {
await interactionReply(embed1, interaction, null);
})
})
}catch(err){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
}
})
}
});
}else if(interaction.customId === 'mypointsbtn'){
var sql = "SELECT * from raiding_run where rr_name = '" + interaction.message.embeds[0].fields[0].value +"' and dc_id = '" + interaction.guild.id + "';";
con.query(sql, async (err, result) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
try{
var sql = "SELECT * from raiding_run_user where rr_id = '" + result[0].rr_id +"' and dc_id = '" + interaction.guild.id + "' and user_id = '" + interaction.user.id+"';";
con.query(sql, async (err, result2) => {
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('My Points')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/548/548481.png')
.addFields({ name: 'Raiding Run', value: result[0].rr_name , inline: false })
.addFields({ name: 'Target Points For Reward', value: '**' + result[0].nb_points_to_winner + '**' , inline: false })
.addFields({ name: 'Reward', value: '**' + result[0].reward + '**' , inline: false })
if(result2.length == 0){
embed1.addFields({ name: 'Your Points', value: "**0**" , inline: false })
}else{
embed1.addFields({ name: 'Your Points', value: "**" + result2[0].points + "**" , inline: false })
}
await interactionReply(embed1, interaction, null);
})
})
}catch(err){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
}
});
}else if(interaction.customId === 'claimr2ebtn'){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
try{
var sql = "SELECT * FROM users where dcid = '" + interaction.user.id + "' and twid is not null" ;
con.query(sql, async (err, result) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
if(result.length == 0){
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Register Now!')
.setURL("https://revengerz.xyz")
.setStyle(ButtonStyle.Link))
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('You Are Not Registered!')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/5836/5836184.png')
.setDescription('1- Head to https://revengerz.xyz\n'+
'2- Connect you wallet\n'+
'3- Go to your profile\n'+
'4- Link your discord and twitter accounts')
await interactionReply(embed1, interaction, row);
})
}else{
var sql = "SELECT * from raiding_run where rr_name = '" + interaction.message.embeds[0].fields[0].value +"' and dc_id = '" + interaction.guild.id + "';";
console.log(sql)
con.query(sql, async (err, result2) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
if(result2[0].finished == 1){
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('Sorry, but this Raiding Run is already finished!')
await interactionReply(embed1, interaction, null);
})
}else{
sql = "SELECT * from user_claim where rr_id = '" + result2[0].rr_id +"' and dc_id = '" + interaction.guild.id +
"' and raid_link = '" + interaction.message.embeds[0].fields[4].value + "' and user_id = '" + interaction.user.id + "';";
con.query(sql, async (err, result4) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
// See if empty or check the unclaimed ones
var likesClaimed = 0
var likeFound = 0
var commentsClaimed = 0
var commentFound = 0
var retweetClaimed = 0
var retweetFound = 0
// Check like
if(parseInt(interaction.message.embeds[0].fields[5].value) != 0){
var xmlHttp = new XMLHttpRequest();
const url = "https://api.twitter.com/2/tweets/"+interaction.message.embeds[0].fields[4].value.split('/')[5].split('?')[0]+"/liking_users";
var initialArray = null;
xmlHttp.open( "GET", url ); // false for synchronous request
xmlHttp.setRequestHeader("Authorization", "Bearer <Set Yours>");
xmlHttp.send();
//****************** Likes ***********************/
xmlHttp.addEventListener("load", function() {
console.log(result[0].twid , ' ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
initialArray = JSON.parse(xmlHttp.response);
var i = 0;
if(initialArray.data){
while(likeFound == 0 && i<initialArray.data.length){
if(initialArray.data[i].id === result[0].twid)
likeFound = 1;
i++;
}
if(likeFound == 1){
likesClaimed = likesClaimed + parseFloat(interaction.message.embeds[0].fields[5].value.replace('**', ''))
}
}
/******************************************* Retweets ************************************************/
xmlHttp = new XMLHttpRequest();
const url = "https://api.twitter.com/2/tweets/"+interaction.message.embeds[0].fields[4].value.split('/')[5].split('?')[0]+"/retweeted_by";
xmlHttp.open( "GET", url ); // false for synchronous request
xmlHttp.setRequestHeader("Authorization", "Bearer <Set Yours>");
xmlHttp.send();
xmlHttp.addEventListener("load", async function() {
initialArray = JSON.parse(xmlHttp.response);
var i = 0;
if(initialArray.data){
while(retweetFound == 0 && i<initialArray.data.length){
if(initialArray.data[i].id === result[0].twid)
retweetFound = 1;
i++;
}
if(retweetFound == 1){
retweetClaimed = retweetClaimed + parseFloat(interaction.message.embeds[0].fields[7].value.replace('**', ''))
}
}
const isCommented = await checkUserComment(interaction.message.embeds[0].fields[4].value.split('/')[5].split('?')[0]
, result[0].twid)
if(isCommented){
commentFound = 1
commentsClaimed = commentsClaimed + parseFloat(interaction.message.embeds[0].fields[6].value.replace('**', ''))
}
if(result4.length != 0){
if(result4[0].like_claimed == 1){
likesClaimed = 0
likeFound = 1
}if(result4[0].comment_claimed == 1){
commentsClaimed = 0
commentFound = 1
}if(result4[0].retweet_claimed == 1){
retweetClaimed = 0
retweetFound = 1
}
}else{
}
var total = likesClaimed + commentsClaimed + retweetClaimed
sql = "SELECT * FROM raiding_run_user where rr_id = '" + result2[0].rr_id + "' and user_id = '" + interaction.user.id + "'"
con.query(sql, async (err, result7) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
if(result7.length == 0){
sql = "INSERT INTO raiding_run_user(user_id, rr_id, dc_id, points, username) VALUES ('" + interaction.user.id +"', '" + result2[0].rr_id + "', '"+
interaction.guild.id + "', " + total + ", '" + interaction.user.username + "')"
}else{
var pp = result7[0].points + total
total = pp
sql = "UPDATE raiding_run_user SET points = " + pp + " where id = " + result7[0].id + ";"
}
con.query(sql, async (err, result5) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
if(result4.length == 0){
sql = "INSERT INTO user_claim(raid_link, rr_id, dc_id, user_id, like_claimed, comment_claimed, retweet_claimed) VALUES ('" + interaction.message.embeds[0].fields[4].value +"', '"
+ result2[0].rr_id + "', '"+ interaction.guild.id + "', " + interaction.user.id + ", " + likeFound + ", " + commentFound + ", " + retweetFound + " )"
}else{
sql = "UPDATE user_claim SET like_claimed = " + likeFound + ", comment_claimed = " + commentFound + ", retweet_claimed = " + retweetFound + " where claim_id = " + result4[0].claim_id
}
con.query(sql, async (err, result5) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
if(result2[0].nb_points_to_winner <= total){
sql = "UPDATE raiding_run SET finished = 1 where rr_name = '" + result2[0].rr_name + "';"
con.query(sql, async (err, result5) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
}
})
}
try{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('R2E Claim')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/9922/9922496.png')
.addFields({ name: 'RR Name', value: interaction.message.embeds[0].fields[0].value , inline: false })
.addFields({ name: 'RR Reward', value: interaction.message.embeds[0].fields[1].value , inline: false })
.addFields({ name: 'Total Points Target', value: interaction.message.embeds[0].fields[2].value , inline: false })
.addFields({ name: 'Your Points', value: "**" + total + "**" , inline: false })
.addFields({ name: 'Like Points Claimed', value: "*" + likesClaimed + " Points*" , inline: false })
.addFields({ name: 'Comment Points Claimed', value: "*" + commentsClaimed + " Points*" , inline: false })
.addFields({ name: 'Retweet Points Claimed', value: "*" + retweetClaimed + " Points*" , inline: false })
await interactionReply(embed1, interaction, null);
})
}catch(err){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
}
})
}
})
}
})
})
})
}
}
})
}
}
})
}
}
})
}catch(error){
sendErrorEmbed(interaction)
}
}else if(interaction.customId === 'claimt2ebtn'){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
try{
var sql = "SELECT * FROM users where dcid = '" + interaction.user.id + "'" ;
con.query(sql, async (err, result) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
if(result.length == 0){
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Register Now!')
.setURL("https://revengerz.xyz")
.setStyle(ButtonStyle.Link))
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('You Are Not Registered!')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/5836/5836184.png')
.setDescription('1- Head to https://revengerz.xyz\n'+
'2- Connect you wallet\n'+
'3- Go to your profile\n'+
'4- Link your discord and twitter accounts')
await interactionReply(embed1, interaction, row);
})
}else{
var sql = "SELECT * from raiding_run where rr_name = '" + interaction.message.embeds[0].fields[0].value +"' and dc_id = '" + interaction.guild.id + "';";
con.query(sql, async (err, result2) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
if(result2[0].finished == 1){
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('Sorry, but this Raiding Run is already finished!')
await interactionReply(embed1, interaction, null);
})
}else{
// Get mission id
var sql = "SELECT * from rr_mission where rr_id = '" + result2[0].rr_id +"' and dc_id = '" + interaction.guild.id + "' and t2e_name = '" + interaction.message.embeds[0].fields[7].value + "';";
con.query(sql, async (err, result3) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
sql = "SELECT * from user_claim where rr_id = '" + result2[0].rr_id +"' and dc_id = '" + interaction.guild.id +
"' and t2e_name = '" + result3[0].t2e_name + "' and user_id = '" + interaction.user.id + "';";
con.query(sql, async (err, result4) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
// See if empty or check the unclaimed ones
var textFound = 0
var hashFound = 0
var initialArray = null;
var xmlHttp = new XMLHttpRequest();
const url = "https://api.twitter.com/2/users/" + result[0].twid + "/tweets?exclude=retweets,replies&max_results=100";
xmlHttp.open( "GET", url ); // false for synchronous request
xmlHttp.setRequestHeader("Authorization", "Bearer <Set Yours>");
xmlHttp.send();
xmlHttp.addEventListener("load", async function() {
initialArray = JSON.parse(xmlHttp.response);
var found = 0;
var t2eClaimed = 0
var total = 0
var i = 0;
var txt = interaction.message.embeds[0].fields[4].value.split(',');
var hashs = interaction.message.embeds[0].fields[5].value.split(',');
if(initialArray.data){
while(found == 0 && i<initialArray.data.length){
textFound = 1;
hashFound = 1;
for(var j=0; j<txt.length; j++){
if(!initialArray.data[i].text.includes(txt[j]))
textFound = 0;
}
for(var j=0; j<hashs.length; j++){
if(!initialArray.data[i].text.includes(hashs[j]))
hashFound = 0;
}
if(textFound && hashFound)
{
found = 1;
t2eClaimed = t2eClaimed = parseFloat(interaction.message.embeds[0].fields[6].value.replace('**', ''))
total = t2eClaimed
}
i++;
}
if(found == 1){
if(result4.length != 0){
if(result4[0].t2e_claimed == 1){
t2eClaimed = 0
found = 1
}
}
sql = "SELECT * FROM raiding_run_user where rr_id = '" + result2[0].rr_id + "' and user_id = '" + interaction.user.id + "'"
con.query(sql, async (err, result7) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
if(result7.length == 0){
sql = "INSERT INTO raiding_run_user(user_id, rr_id, dc_id, points, username) VALUES ('" + interaction.user.id +"', '" + result2[0].rr_id + "', '"+
interaction.guild.id + "', " + t2eClaimed + ", '" + interaction.user.username + "')"
}else{
var pp = result7[0].points + t2eClaimed
total = pp
sql = "UPDATE raiding_run_user SET points = " + pp + " where id = " + result7[0].id + ";"
}
con.query(sql, async (err, result5) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
if(result4.length == 0){
sql = "INSERT INTO user_claim(t2e_name, rr_id, dc_id, user_id, t2e_claimed) VALUES ('" + interaction.message.embeds[0].fields[7].value +"', '"
+ result2[0].rr_id + "', '"+ interaction.guild.id + "', " + interaction.user.id + ", " + found + " )"
}else{
sql = "UPDATE user_claim SET t2e_claimed = " + found + " where claim_id = " + result4[0].claim_id
}
con.query(sql, async (err, result5) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
if(result2[0].nb_points_to_winner <= total){
sql = "UPDATE raiding_run SET finished = 1 where rr_name = '" + result2[0].rr_name + "';"
con.query(sql, async (err, result5) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
}
})
}
try{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('T2E Claim')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/2580/2580225.png')
.addFields({ name: 'RR Name', value: interaction.message.embeds[0].fields[0].value , inline: false })
.addFields({ name: 'RR Reward', value: interaction.message.embeds[0].fields[1].value , inline: false })
.addFields({ name: 'Total Points Target', value: interaction.message.embeds[0].fields[2].value , inline: false })
.addFields({ name: 'Your Points', value: "**" + total + "**" , inline: false })
.addFields({ name: 'T2E Points Claimed', value: "*" + t2eClaimed + " Points*" , inline: false })
await interactionReply(embed1, interaction, null);
})
}catch(err){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
}
})
}
})
}
})
}else{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('T2E Claim')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/2580/2580225.png')
.addFields({ name: 'RR Name', value: interaction.message.embeds[0].fields[0].value , inline: false })
.addFields({ name: 'RR Reward', value: interaction.message.embeds[0].fields[1].value , inline: false })
.addFields({ name: 'Total Points Target', value: interaction.message.embeds[0].fields[2].value , inline: false })
.addFields({ name: 'T2E Points Claimed', value: "*" + t2eClaimed + " Points*" , inline: false })
await interactionReply(embed1, interaction, null);
})
}
}
})
}
})
}
})
// Get users claims
}
}
})
}
}
})
}catch(error){
sendErrorEmbed(interaction)
}
}
}
else if (interaction.isModalSubmit()) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
if (interaction.customId === 'createrrmodal') {
var sql = "INSERT INTO raiding_run (dc_id, rr_name, reward, nb_points_to_winner) " +
"VALUES ('" + interaction.guild.id + "', '"+ interaction.fields.getTextInputValue('rrnameinput')
+"', '"+ interaction.fields.getTextInputValue('rrrewardinput') + "', '"+ interaction.fields.getTextInputValue('nbpointsinput') + "')";
con.query(sql, async (err, result) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
else{
var sql = "SELECT * FROM rr_subs where dc_id = '" + interaction.guild.id + "'";
con.query(sql, async (err, result2) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
if(result2.length != 0){
var consumed = result2[0].consumed + 1
var sql = "UPDATE rr_subs set consumed = " + consumed + " where dc_id = '" + interaction.guild.id + "'";
con.query(sql, async (err, result2) => {
if (err) {
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}else{
try{
getProject(interaction.guild.id).then(async res => {
let embed1 = null
console.log(res , ' ******************')
if(res == null){
embed1 = embed()
}else{
embed1 = embed55(res)
}
embed1.setTitle('RR Creation')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/753/753317.png')
.setDescription('Your RR is created with success!')
.addFields({ name: 'RR Name', value: interaction.fields.getTextInputValue('rrnameinput') , inline: false })
.addFields({ name: 'RR Reward', value: interaction.fields.getTextInputValue('rrrewardinput') , inline: false })
.addFields({ name: 'Total Points Target', value: interaction.fields.getTextInputValue('nbpointsinput') , inline: false })
await interactionReply(embed1, interaction, null);
})
}catch(err){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
}
})
}
}
})
}
});
/*clientPg.query("SELECT * FROM bankconfig where dcid = '" + interaction.guild.id + "'").then(async res => {
const data5 = res.rows;
if(data5.length == 0)
{
// insert
const res = insetConfig(interaction.guild.id,
interaction.fields.getTextInputValue('tokenaddinput'),
interaction.fields.getTextInputValue('tokennameinput'),
interaction.fields.getTextInputValue('claiminput'),
interaction.fields.getTextInputValue('dailyrewardsinput'),
interaction.fields.getTextInputValue('bankimageinput'))
if(res)
{
try{
let embed1 = embed()
embed1.setTitle('Bank Configuration')
.setDescription('Your bank has been configured with success')
.addFields({ name: 'Token Address', value: interaction.fields.getTextInputValue('tokenaddinput') , inline: false })
.addFields({ name: 'Token Name', value: interaction.fields.getTextInputValue('tokennameinput') , inline: false })
.addFields({ name: 'Minimum to Claim', value: interaction.fields.getTextInputValue('claiminput') , inline: false })
.addFields({ name: 'Daily rewards', value: interaction.fields.getTextInputValue('dailyrewardsinput') , inline: false })
await interactionReply(embed1, interaction, null);
}catch(err){
await interaction.deferReply({ ephemeral: true }).catch(err => {});
sendErrorEmbed(interaction);
}
}
else{
}
}
else{
// update
try{
const res = updateConfig(interaction.guild.id,
interaction.fields.getTextInputValue('tokenaddinput'),