-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-v12.js
2843 lines (2821 loc) · 113 KB
/
app-v12.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
//CODE BEGINS HERE
//includes
const Discord = require('discord.js');
const fs = require('fs');
const Canvas = require('canvas');
const shuffle = require("shuffle-array");
//dependencies and setupconst
const config = require('./config.json');
const client = new Discord.Client();
const { Users, CurrencyShop, Waifus, WaifuItems, Transactions, PlantedCurrency } = require('./dbObjects');
const { Op } = require('sequelize');
const currency = new Discord.Collection();
const waifushop = require('./waifus/waifushop.json');
const spevent = require('./spevent/spevent.json');
//main prefix
const PREFIX = config.PREFIX;
//special 'purple marisa' prefix
const PMORS = config.PMORS;
//global variables
var running = 1;
var bj_tables = [];
//shenanigans
Reflect.defineProperty(currency, 'add', {
value: async function add(id, amount, reason = false) {
const user = currency.get(id);
// add currency transaction IF there is reason
if (reason) {
await Transactions.create({
user_id: id,
amount: amount,
reason: reason
});
}
if (user) {
user.balance += Number(amount);
return user.save();
}
// prevent error when someone sent a message while the bot is initializing
const newUser = await Users.create({ user_id: id, balance: amount })
.catch(e => undefined);
if (!newUser) return false;
currency.set(id, newUser);
return newUser;
},
});
Reflect.defineProperty(currency, 'getBalance', {
value: function getBalance(id) {
const user = currency.get(id);
return user ? user.balance : 0;
},
});
// end of shenanigans
// function to check user becaosue it took a lot of sapce and useful
function checkUser(user, message) {
//try to get the user as it is
var usr = message.guild.members.cache.get(user);
//if there is an user argument and it's not formated right do some checks
if (!usr && user) {
// get cache and sort them based on birth time, put bots on the bottom
// this will prioritze users over bot and shit
const cache = message.guild.members.cache
.sort((a, b) => a.user.createdTimestamp - b.user.createdTimestamp)
.sort((a, b) => a.user.bot - b.user.bot);
try {
//try to find user by tag
//modified to prevent gift issues also who tf uses tag???
usr = cache.find(e => e.user.tag.toLowerCase() === user.toLowerCase())
//try to find user by displayName
|| cache.find(e => e.displayName.toLowerCase().indexOf(user.toLowerCase()) > -1)
//try to find user by username
|| cache.find(e => e.user.username.toLowerCase().indexOf(user.toLowerCase()) > -1);
} catch(err) {
return false;
}
}
return usr;
}
//function to remove user reactions from message
async function remove_react(user_id, message){
//get user reactions to the message
const userReactions = message.reactions.cache.filter(reaction => reaction.users.cache.has(user_id));
try {
//iterate through the reactions for those of the user
for (const reaction of userReactions.values()) {
//remove reaction
await reaction.users.remove(user_id);
}
} catch (error) {
console.error('Failed to remove reactions.');
}
}
//function checking for Blackjack games starting/timing out/uhh (every second)
setInterval(() => {
//iterate through all the currecnt blackjack tables (gameinstances)
bj_tables.forEach((item, i) => {
//define current time in ms
let time = Date.now();
//initialize the embed
var embed = new Discord.MessageEmbed()
.setColor(0x00AE86)
.setThumbnail(config.thumb);
//check if game has already started
if (item.started) {
//checks for players and their current states
var players_in_game = false;
item.player_state.forEach((state, j) => {
//check if it is the player's turn and he took more than 20 seconds
if (item.player_state[j] === 1 && time - item.player_time > 20000){
//set the player state to timed out (4)
//set it to stand instead
item.player_state[j] = 5;
//reset the timer
item.player_time = time;
//pass the turn to the next player (no, i mean the next one that can play)
temp = true;
for (var k = j; k < item.player_state.length; k++) {
if (temp) {
if (item.player_state[k] === 0){
item.player_state[k] = 1;
temp = false;
}
}
}
}
//check if there are any players left to make a move
if (state === 0 || state === 1) {
players_in_game = true;
}
});
//there are still moves to be made, so get data>calculate wins/loses>make embed
if (players_in_game) {
//add title and footer to embed
embed.setTitle(`Blackjack table - Playing`)
.setFooter(`React 🇸 to stand or 🇭 to hit. Bet is ${item.bet} mimicoinz.`);
//add the house hand and it's value to be displayed
embed.addField(`House hand: ${item.househand[0].value[1]}`,`${item.househand[0].rank}${item.househand[0].emoji}`, true);
//for each player, display the cards and calculate the sum and soft sum
item.players.forEach((player, j) => {
//helper vars
var cards = '';
var sum1 = 0;
var sum2 = 0;
//check if player is waiting his turn
if (item.player_state[j] === 0) {
//create his deck
item.playerhands[j].forEach((card, k) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
item.player_totals[j][0] = sum1;
item.player_totals[j][1] = sum2;
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`${player.tag}'s hand: ${sum}`,`${cards}`);
} else if (item.player_state[j] === 1) {
//check if player is still in game and it is his turn
item.playerhands[j].forEach((card, k) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
item.player_totals[j][0] = sum1;
item.player_totals[j][1] = sum2;
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//check for win/loss
if ((sum1 > 21) && (sum2 > 21)) {
//lose
item.player_state[j] = 2;
embed.addField(`LOST - ${player.tag}'s hand: ${sum})`,`${cards}`);
//give the turn to the next player
temp = true; //helper var telling us when to stop
//iterate through the players, starting from the next one
for (var k = j+1; k < item.player_state.length; k++) {
if (temp) {
if (item.player_state[k] === 0){
//set his state to HIS TURN (1)
item.player_state[k] = 1;
//i'm sure there's a better way to do this
temp = false;
}
}
}
//now the same thing, but from the end to the current position
for (var k = 0; k < j; k++) {
if (temp) {
if (item.player_state[k] === 0){
//set new state
item.player_state[k] = 1;
temp = false;
}
}
}
} else if ((sum1 === 21) || (sum2 === 21) || (item.playerhands[j].length > 4)) {
//player wins on blackjack or 5 cards
item.player_state[j] = 3;
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`WON - ${player.tag}'s hand: ${sum})`,`${cards}`);
//give the turn to the next player
temp = true; //helper var telling us when to stop
//iterate through the players, starting from the next one
for (var k = j+1; k < item.player_state.length; k++) {
if (temp) {
if (item.player_state[k] === 0){
//set his state to HIS TURN (1)
item.player_state[k] = 1;
//i'm sure there's a better way to do this
temp = false;
}
}
}
} else {
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`${player.tag}'s hand: ${sum}`,`${cards}`);
embed.setTitle(`Player to move: ${player.tag}`);
}
} else if (item.player_state[j] === 2) {
//check if player has lost
item.playerhands[j].forEach((card, k) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`LOST - ${player.tag}'s hand: ${sum}`,`${cards}`);
} else if (item.player_state[j] === 3) {
//check if player has already won
item.playerhands[j].forEach((card, k) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`WON - ${player.tag}'s hand: ${sum}`,`${cards}`);
} else if (item.player_state[j] === 5){
//check if player is still in game but will not receive any new cards because he 'stands'
item.playerhands[j].forEach((card, k) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`STAND - ${player.tag}'s hand: ${sum}`,`${cards}`);
}
});
//edit message with embed
item.message.edit(embed)
}
//there are no more players to make moves, give cards to the house and end the game
else {
//initialize endgame embed fields
embed.setTitle(`Blackjack table - Finished!`).setFooter('Game over!');
//get the value of the house hand
var house_total = item.househand[0].value[1];
//give the house her cards
do {
//give a card to the house
item.househand.push(item.deck[0]);
//calculate the new totals
house_total += item.househand[item.househand.length - 1].value[1];
//remove card from deck
item.deck.splice(0, 1);
} while (house_total < 17);
//check if bust or not
var bust = false;
if (house_total > 21) bust = true;
//display the house results
//helper vars for the house section
var house = '';
var sum = 0;
//iterate through the house hand
item.househand.forEach((card, j) => {
//create the deck to show on screen
house += `${card.rank}${card.emoji} `;
//calculate the sum of the cards and the sum
sum += card.value[1];
});
//add field to embed
embed.addField(`House hand: ${sum}`,`${house}`, true);
//tally wins/loses
if (bust) {
//house lost
item.players.forEach((player, j) => {
if (item.player_state[j] === 2) {
//player lost - bust
currency.add(player.id, -(Math.floor(item.bet)), `Blackjack`);
currency.add(config.mima, Math.floor(item.bet));
} else if (item.player_state[j] === 3) {
//player won - blackjack or 5 cards
currency.add(player.id, Math.floor(item.bet*0.5), `Blackjack`);
currency.add(config.mima, -(Math.floor(item.bet*0.5)));
} else if (item.player_state[j] === 5) {
//player won - stand
currency.add(player.id, Math.floor(item.bet*0.5), `Blackjack`);
currency.add(config.mima, -(Math.floor(item.bet*0.5)));
//set state for embed
item.player_state[j] = 3;
}
});
} else {
//house not out of the game
item.players.forEach((player, j) => {
if (item.player_state[j] === 2) {
//player lost - bust
currency.add(player.id, -(Math.floor(item.bet)), `Blackjack`);
currency.add(config.mima, Math.floor(item.bet));
} else if (item.player_state[j] === 3) {
//player won - blackjack
currency.add(player.id, Math.floor(item.bet*0.5), `Blackjack`);
currency.add(config.mima, -(Math.floor(item.bet*0.5)));
} else if (item.player_state[j] === 5) {
//check the player's hand value compared to the the house's
if (((item.player_totals[j][0] < 21)&&(item.player_totals[j][0] > house_total))||((item.player_totals[j][1] < 21)&&(item.player_totals[j][1] > house_total))) {
//player won - stand
currency.add(player.id, Math.floor(item.bet*0.5), `Blackjack`);
currency.add(config.mima, -(Math.floor(item.bet*0.5)));
//set state for embed
item.player_state[j] = 3;
} else if ((item.player_totals[j][0] === house_total)||(item.player_totals[j][1] === house_total)) {
//player draw - stand
//set state for embed
item.player_state[j] = 6;
} else {
//player lost - stand
currency.add(player.id, -(Math.floor(item.bet)), `Blackjack`);
currency.add(config.mima, Math.floor(item.bet));
//set state for embed
item.player_state[j] = 2;
}
}
});
}
//iterate through all the players
item.players.forEach((player, k) => {
var cards = '';
var sum1 = 0;
var sum2 = 0;
if (item.player_state[k] === 2) {
//check if player has lost
item.playerhands[k].forEach((card, l) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`LOST - ${player.tag}'s hand: ${sum}`,`${cards}`);
} else if (item.player_state[k] === 3) {
//check if player has already won
item.playerhands[k].forEach((card, l) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`WON - ${player.tag}'s hand: ${sum}`,`${cards}`);
} else if (item.player_state[k] === 6) {
//check if player and the house have reached a DRAW
item.playerhands[k].forEach((card, l) => {
cards += `${card.rank}${card.emoji} `;
sum1 += card.value[0];
sum2 += card.value[1];
});
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`DRAW - ${player.tag}'s hand: ${sum}`,`${cards}`);
}
});
//edit the message with the new embed
item.message.edit(embed);
//remove the game from the array
bj_tables.splice(i, 1);
}
} else {
//game exists, but has not yet begun
//check to see if the game was created more than 10s ago
if (time - item.time > 10000) {
//start the game
item.started = true;
//add title and footer to embed
embed.setTitle(`Blackjack table - Playing`)
.setFooter(`React 🇸 to stand or 🇭 to hit. Bet is ${item.bet} mimicoinz. Win rate is 3/2.`);
//shuffle the deck
item.deck = shuffle(item.deck)
//give the players the first 2 cards
item.players.forEach((player, j) => {
item.playerhands[j][0] = item.deck[0];
item.playerhands[j][1] = item.deck[1];
item.deck.splice(0, 2);
});
//give the house one card
item.househand.push(item.deck[0]);
item.deck.splice(0, 1);
//add the house hand and it's value to be displayed
embed.addField(`House hand: ${item.househand[0].value[1]}`,`${item.househand[0].rank}${item.househand[0].emoji}`, true);
//give teh first player in the array the turn (state 1)
item.player_state[0] = 1;
//for each player, display the cards and calculate the sum and soft sum
item.players.forEach((player, j) => {
//helper vars
var cards = '';
var sum1 = 0;
var sum2 = 0;
//iterate through the player's hand
item.playerhands[j].forEach((card, k) => {
//create the deck to show on screen
cards += `${card.rank}${card.emoji} `;
//calculate the sum of the cards and the soft sum
sum1 += card.value[0];
sum2 += card.value[1];
});
//store the hand value
item.player_totals[j][0] = sum1;
item.player_totals[j][1] = sum2;
//check for blackjack
if (sum1 === 21 || sum2 === 21) {
//check if it is the player's turn
if (item.player_state[j] === 1) {
//pass the turn to someone else (if any)
temp = true; //helper var telling us when to stop
//iterate through the players, starting from the next one
for (var k = j+1; k < item.player_state.length; k++) {
if (temp) {
if (item.player_state[k] === 0){
//set his state to HIS TURN (1)
item.player_state[k] = 1;
//i'm sure there's a better way to do this
temp = false;
}
}
}
//now the same thing, but from the end to the current position
for (var k = 0; k < j; k++) {
if (temp) {
if (item.player_state[k] === 0){
//set new state
item.player_state[k] = 1;
temp = false;
}
}
}
}
//set him as winner
item.player_state[j] = 3;
}
//if the sums are different, show them both, otherwise show only one
if (sum1 === sum2) {
var sum = `${sum1}`;
} else {
var sum = `${sum1}(${sum2})`;
}
//add field to embed
embed.addField(`${player.tag}'s hand: ${sum}`,`${cards}`);
//tell who's the next player to make a move
if (item.player_state[j] === 1) embed.setTitle(`Player to move:`, `${player.tag}`);
});
//edit message with embed
item.message.edit(embed)
//add te reactions to the message
item.message.react('🇸');
item.message.react('🇭');
//reset the player_time to the current time
item.player_time = time;
} else {
//just update the embed to make sure anyone that joins is shown
embed.setTitle(`Blackjack table - Getting ready`)
.setFooter(`React ✅ to join. Bet is ${item.bet} mimicoinz. Win rate is 3/2.`);
embed.addField(`Status:`,`Waiting for game start...`);
//iterate through all the players
var player_names = ``;
item.players.forEach((player, j) => {
player_names += `${player.tag}\n`
});
embed.addField(`Current players:`,`${player_names}`);
//replace the embed with the new one we just made
item.message.edit(embed);
}
}
});
}, 1000);
//on start
client.once('ready', async () => {
//fill up the user table and their money
const storedBalances = await Users.findAll();
storedBalances.forEach(b => currency.set(b.user_id, b));
// NOTE: cache every users this bot knows and put em in datbase
const inactives = client.users.cache.filter(e => storedBalances.map(m => m.user_id));
await inactives.forEach(async user => await currency.add(user.id, 0));
//set mima's status
client.user.setActivity(`!help`, { type: 'WATCHING' })
.then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
.catch(console.error);
//cli greeting message
console.log(`${client.user.tag} reincarnated!`);
//greeting message in the main channel
// config.CHANNELID.forEach(channel_id => {
// client.channels.cache.get(channel_id).send(`Pfew, I'm back! >v<`);
// });
});
//////////////////////////////////////////////////////////////////////////embeds
{
//create the main help embed
var help = new Discord.MessageEmbed()
.setTitle("Availible Commands")
.setAuthor(`Mima Sama the Bot Spirit`, config.thumb)
.setColor(0x00AE86)
.setThumbnail(config.thumb);
help.addField('\u200B',`${config.help[0]}`);
//create the meme help embed
var helpm = new Discord.MessageEmbed()
.setTitle("Silly Commands")
.setAuthor(`Mima Sama the Bot Spirit`, config.thumb)
.setColor(0x00AE86)
.setThumbnail(config.thumb);
helpm.addField(`\u200B`, `${config.help[1]}`);
//create the xp help embed
var helpx = new Discord.MessageEmbed()
.setTitle("XP Commands")
.setAuthor(`Mima Sama the Bot Spirit`, config.thumb)
.setColor(0x00AE86)
.setThumbnail(config.thumb);
helpx.addField(`\u200B`, `${config.help[2]}`);
//create the currency help embed
var helpc = new Discord.MessageEmbed()
.setTitle("Currency Commands")
.setAuthor(`Mima Sama the Bot Spirit`, config.thumb)
.setColor(0x00AE86)
.setThumbnail(config.thumb);
helpc.addField(`\u200B`, `${config.help[3]}`);
//create the help embed
var helpg = new Discord.MessageEmbed()
.setTitle("Gambling Commands")
.setAuthor(`Mima Sama the Bot Spirit`, config.thumb)
.setColor(0x00AE86)
.setThumbnail(config.thumb);
helpg.addField(`\u200B`, `${config.help[4]}`);
//create the purple marisa help embed
var helppm = new Discord.MessageEmbed()
.setTitle("Purple Marisa Commands")
.setAuthor(`Mima Sama the Bot Spirit`, config.thumb)
.setColor(0x00AE86)
.setThumbnail(config.thumb);
helppm.addField(`\u200B`, `${config.help[5]}`);
//create the waifu help embed
var helpwf = new Discord.MessageEmbed()
.setTitle("Waifu Commands")
.setAuthor(`Mima Sama the Bot Spirit`, config.thumb)
.setDescription("List of commands availible")
.setColor(0x00AE86)
.setThumbnail(config.thumb);
helpwf.addField(`\u200B`, `${config.help[6]}`);
}
///////////////////////////////////////////////////////////////////end of embeds
//tools module
client.on('message', async message => {
//check if owner
if (message.author.id !== config.BOTOWNER) return;
//mkae sure message is not in DM
if (message.channel.type === 'dm') return;
//helper var
mes = message.content;
//make sure the message is sent in the right channel
if (!(config.CHANNELID.includes(message.channel.id))) return;
//make sure the command starts with PREFIX
if (!mes.startsWith(PREFIX)) return;
//slice the PREFIX
const input = mes.slice(PREFIX.length).trim();
//check that the command actually has something in it left
if (!input.length) return;
//regex madness (check that there is a commad as a word and maybe some args after it)
if (!input.match(/(\$|\w+)\s*([\s\S]*)/)) return;
//then store the command and the commandArgs
var [, command, commandArgs] = input.match(/(\$|\w+)\s*([\s\S]*)/);
//convert command to LowerCase
command = command.toLowerCase();
//check for the start/stop commands
if (command === 'sleep') {
running = 0;
return message.channel.send(`Finally, some rest...\n (ᴗ˳ᴗ)`);
}
if (command === 'wake') {
running = 1;
return message.channel.send(`All right, all right, I'm up!\nヽ( ´O`)ゞ`);
}
});
// currency module
client.on('message', async message => {
//check if bot running
if (!running) return;
//make sure it's not a bot
if (message.author.bot) return;
//mkae sure message is not in DM
if (message.channel.type === 'dm') return;
//check taht the user isn't banned
if (message.member.roles.cache.find(f => f.name === config.banned)) return;
//helper var
mes = message.content;
//adding currency for every message that is not a bot command
//(if your server uses other bots make sure to include their prefix in this)
if (!mes.startsWith(PREFIX) && !mes.startsWith('$')){
currency.add(message.author.id, config.moni);
}
//PLANT COMMAND
//check that mima actually has spare cash to give
if (currency.getBalance(config.mima) > 10000) {
//if he's lucky, give him 1000 coins
if (Math.floor(Math.random()*config.plant) === 4) {
config.CHANNELID.forEach(channel => {
if (message.guild.channels.cache.get(channel)) {
client.channels.cache.get(channel).send(`You won ${config.plant}💰, ${message.author}! Yay!`);
currency.add(message.author.id, config.plant, `Random Mima gift`);
currency.add(config.mima, -config.plant);
}
});
}
}
//make sure the message is sent in the right channel
if (!(config.CHANNELID.includes(message.channel.id))) return;
//make sure the command starts with PREFIX
if (!mes.startsWith(PREFIX)) return;
//slice the PREFIX
const input = mes.slice(PREFIX.length).trim();
//check that the command actually has something in it left
if (!input.length) return;
//regex madness (check that there is a commad as a word and maybe some args after it)
if (!input.match(/(\$|\w+)\s*([\s\S]*)/)) return;
//then store the command and the commandArgs
var [, command, commandArgs] = input.match(/(\$|\w+)\s*([\s\S]*)/);
//convert command to LowerCase
command = command.toLowerCase();
//check sender's balance or the balance of someone tagged in the message if any
if (command === 'balance' || command === 'cash' || command === "$") {
// if any mentions, else checkUser, else get self
// and also get user object (always returns user)
const target = message.mentions.users.first()
|| checkUser(commandArgs, message)?.user
|| message.author;
return message.channel.send(
new Discord.MessageEmbed()
.setColor(0x00AE86)
.setTitle(`**${target.tag}** has **${currency.getBalance(target.id)}💰**`)
);
}
//check user's role inventory
else if (command === 'roles') {
// if any mentions, else checkUser, else get self
// and also get user object (always returns user)
const target = message.mentions.users.first()
|| checkUser(commandArgs, message)?.user
|| message.author;
//get the user's data from the table
const user = await Users.findOne({ where: { user_id: target.id } });
const items = await user.getItems();
//send the users inventory
return message.channel.send(
new Discord.MessageEmbed()
.setColor(0x00AE86)
.setTitle(
// checks if items i s empty
!(items.length) ? `${target.tag} has no roles!` :
`${target.tag} currently owns the following: ` +
`${items.map(t => `${t.item.name}`).join(', ')}`
)
);
}
//transferring mimicoinz to someone else
else if (command === 'transfer' || command === 'give') {
//getting the current amount of the user making the transfer
const current = currency.getBalance(message.author.id);
// looks for any string that isnt half, all or a discord id
const targetStr = commandArgs.match(/\b(?!(half|all|(?!\d{18})\d+))\S+\b/gi)?.[0];
// remove targetStr then we good
// looks for half, all or number that isnt (possible) discord id
const amountStr = commandArgs
.replace(targetStr, '')
.match(/\b(?!\d{18})(half|all|\d+)\b/gi)?.[0];
if (!amountStr || !targetStr) return message.channel.send(`Sorry ${message.author}, it doesn't work this way...`);
// getting the give message
const msg = commandArgs.replace(amountStr, '').replace(targetStr, '').trim();
// self-explanatoryu
const target = checkUser(targetStr, message)?.user
|| message.author;
//check to see if sender and receiver are different users
if (message.author === target) return message.channel.send(`Sorry ${message.author}, it doesn't work this way...`);
// if all, half, else parse integer
const amount = amountStr === 'all' ? current
: amountStr === 'half' ? Math.floor(current / 2)
: parseInt(amountStr);
//transfer amount checks
//if null or not a number, NAH NO NEED TO
//if (!amount || isNaN(amount)) return message.channel.send(`Sorry ${message.author.tag}, that's an invalid amount`);
if (amount > current) return message.channel.send(`Sorry ${message.author.tag} you don't have that much.`);
if (amount <= 0) return message.channel.send(`Please enter an amount greater than zero, ${message.author.tag}`);
//do the adding and substracting
await currency.add(message.author.id, -amount, `Given to ${target.tag} ${msg}`);
currency.add(target.id, amount, `Received from ${message.author.tag} ${msg}`);
//done
return message.channel.send(
new Discord.MessageEmbed()
.setColor(0x00AE86)
.setTitle(`Successfully transferred ${amount}💰 to ${target.tag}. Your current balance is ${currency.getBalance(message.author.id)}💰`)
);
}
//buying roles from the shop
else if (command === 'buy') {
//get the item from the table
const item = await CurrencyShop.findOne({ where: { name: { [Op.like]: commandArgs } } });
//check the valitidy of the item
if (item === null) return message.channel.send('That item doesn\'t exist.');
//balance check
if (item.cost > currency.getBalance(message.author.id)) {
return message.channel.send(`You don't have enough coins, ${message.author}`);
}
//get the user data from teh table
const user = await Users.findOne({ where: { user_id: message.author.id } });
//check to see if the server has the role already
const role = message.guild.roles.cache.find(guild_role => guild_role.name == item.name);
//chekc if role exists on the server
try {
//check if the user already owns the role
if (message.member.roles.cache.find(f => f.name === role.name)) return message.channel.send('You already have the "' + item.name + '" role.')
//update the ballance
currency.add(message.author.id, -item.cost, `Bought role`);
currency.add(config.mima, item.cost);
//give the user his item
await user.addItem(item);
//assign the user his role
message.member.roles.add(role).catch(console.error);
//confirm the purchase
message.channel.send(`You've bought ${item.name}`);
} catch (e) {
if (item.name === `Purple Marisa`) {
//get the user's roles
const items = await user.getItems()
//check if he already owns the role
items.forEach(item => {
if (item.name === item) {
return message.channel.send('You already have the "' + item.name + '" role.');
}
});
//update the ballance
currency.add(message.author.id, -item.cost, `Bought role`);
currency.add(config.mima, item.cost);
//give the user his item
await user.addItem(item);
//confirm the purchase
return message.channel.send(`You've bought ${item.name}`);
} else {
return message.channel.send('This role is not yet present on this server.');
}
}
}
//displaying the shop
else if (command === 'shop') {
//get items from the mimishop
const items = await CurrencyShop.findAll();
//create the embed
var shop = new Discord.MessageEmbed()
.setTitle(`Welcome to the mimishop`)
.setColor(0x00AE86)
.setThumbnail(config.thumb)
.setFooter(`use !buy [rolename] to get one of those roles`);
//check to see which roles are present on the server where the req was made
////check if return is empty
var empty = true;
////for loop to iterate thought the items
items.forEach(item => {
const role = message.guild.roles.cache.find(guild_role => guild_role.name == item.name);
try {
role.name;
shop.addField(`"${item.name}": ${item.cost} 💰`,`${item.desc}`);
empty = false;
} catch (e){
true == true
}
});
//create field for empty shop, adding only Purple Marisa role to it.
if (empty) shop.addField(`"Purple Marisa": 100000 💰`,`Gives "Purple Marisa" role and access to unique Mima-bot commands`)
//send embed to the channel
return message.channel.send(shop);
}
//displaying the top 10 leaderboard
else if (command === 'leaderboard' || command === 'lb' ) {
// get number from arguments, else 1
const page = parseInt(commandArgs) || 1;
if (page <= 0) return message.channel.send(`Please enter a page number greater than zero ${message.author.tag}`);
// first page always starts from 0
// NOTE: learn basic addition and multiplication
const offset = page * 10 - 10;
const total = Math.floor(message.guild.memberCount / 10) + 1;
if (page > total) return message.channel.send(`Sorry but that page doesn't exist.`);
// get only this guild's members collection
const members = message.guild.members.cache;
// the currency collection is a mishmash of members from other server
// find where the keys intersect with members collection
const filtered = members.intersect(currency);
// sort the list
filtered.sort((a, b) => b.balance - a.balance);
// make it into an array, paginate, map to string, then join with newlines
const list = filtered.toJSON()
.slice(offset, offset + 10)
.map(
(u, i) => `${i + offset + 1}. ${(client.users.cache.get(u.user_id).tag)}: **${u.balance}**💰`
).join('\n');
return message.channel.send(
new Discord.MessageEmbed()
.setTitle('Leaderboard')
.setAuthor(client.user.username, config.thumb)
.setDescription(list)
.setFooter(`Page ${page} of ${total}`)
);
}
//give command
else if (command === 'award') {
//check that owner gives the command
if(message.author.id !== config.BOTOWNER) return message.reply("You're not Mima Sama, you can't do that!");
//get the amount of cash mima has (needed in case of all or half)
const current = currency.getBalance(config.mima);
// looks for half, all or (possible) discord id
const amountStr = commandArgs.match(/\b(?!\d{18})(half|all|\d+)\b/gi)?.[0];
// looks for any string that isnt half, all or a discord id
const targetStr = commandArgs.match(/\b(?!(half|all|(?!\d{18})\d+))\S+\b/gi)?.[0];
// just in case regex doesnt work
if (!amountStr || !targetStr) return message.channel.send(`Sorry ${message.author}, it doesn't work this way...`);
// self-explanatoryu
const target = checkUser(targetStr, message)?.user
|| message.author;
// if all, half, else parse integer
const amount = amountStr === 'all' ? current
: amountStr === 'half' ? Math.floor(current / 2)
: parseInt(amountStr);
//check that mima is not the target of it
if (target === client.user) return message.channel.send(`Huh? Is this a bribe? ( •᷄ὤ•᷅)?`);
//award amount checks
if (amount <= 0) return message.channel.send(`Please enter an amount greater than zero, ${message.author}`);
//do the adding and substracting
currency.add(config.mima, -amount);
currency.add(target.id, amount, `Awarded by Mima`);
//done
return message.channel.send(`I have gifted ${amount}💰 to ${target.tag}. My current balance is ${currency.getBalance(client.user.id)}💰`);
}
//take command
else if (command === 'take') {
//check that owner gives the command
if(message.author.id !== config.BOTOWNER) return message.reply("You're not Mima Sama, you can't do that!");
// looks for half, all or (possible) discord id
const amountStr = commandArgs.match(/\b(?!\d{18})(half|all|\d+)\b/gi)?.[0];
// looks for any string that isnt half, all or a discord id
const targetStr = commandArgs.match(/\b(?!(half|all|(?!\d{18})\d+))\S+\b/gi)?.[0];
// just in case regex doesnt work
if (!amountStr || !targetStr) return message.channel.send(`Sorry ${message.author}, it doesn't work this way...`);
// self-explanatoryu
const target = checkUser(targetStr, message)?.user
|| message.author;
const current = currency.getBalance(target.id);
// if all, half, else parse integer
const amount = amountStr === 'all' ? current
: amountStr === 'half' ? Math.floor(current / 2)
: parseInt(amountStr);
//check that mima is not the transferTarget
if (target === client.user) return message.channel.send('Huh? NOT MY MONIES PLS 。゚・(>﹏<)・゚。');
//award amount checks
if (amount <= 0) return message.channel.send(`Please enter an amount greater than zero, ${message.author}`);
//do the adding and substracting
currency.add(config.mima, amount);
currency.add(target.id, -amount, `Taken by Mima`);
//done
return message.channel.send(`I have taken ${amount}💰 from ${target.tag}. My current balance is ${currency.getBalance(config.mima)}💰`);
}
//eliminate currency from the economy
else if (command === 'destroy') {
//check that owner gives the command
if(message.author.id !== config.BOTOWNER) return message.reply("You're not Mima Sama, you can't do that!");
//amount checks
//if null or not a number
if (!commandArgs || isNaN(commandArgs)) return message.channel.send(`Sorry ${message.author}, that's an invalid amount`);
//do the substracting
currency.add(config.mima, -commandArgs);
//done
return message.channel.send(`I have destroyed ${commandArgs}💰. My current balance is ${currency.getBalance(config.mima)}💰`);
}
//account history
else if (command === 'curtrs') {
// looks for last, or any number that isnt discord id
const pageStr = commandArgs.match(/\b(?!\d{18})(last|\d+)\b/gi)?.[0];
// looks for any string that isnt last, look for possible discord id
const targetStr = commandArgs.match(/\b(?!(last|(?!\d{18})\d+))\S+\b/gi)?.[0];
// gets mentions, else check from string, else get self
const target = message.mentions.users.first()
|| checkUser(targetStr, message)?.user
|| message.author;
// getting transactions from database
const transactions = await Transactions.findAll({
where: { user_id: target.id },
order: [['id', 'DESC']],
raw: true
});
const page = pageStr === 'last'
? Math.floor(transactions.length / 10) + 1
: parseInt(pageStr) || 1;
if (page <= 0) return message.channel.send(`Please enter a page number greater than zero ${message.author.tag}`);
const offset = page * 10 - 10;
const total = Math.floor(transactions.length / 10) + 1;
if (page > total) return message.channel.send(`Sorry but that page doesn't exist.`);
// paginate, map to string, then join with newlines
const transactionlist = transactions
.slice(offset, offset + 10)
.map(
t => `\`${ t.amount >= 0 ? '🟢' : '🔴'} ` +
`${new Date(t.createdAt).toLocaleString()}\` **${t.amount}**\n` +
`${t.reason}`
)
.join('\n')
|| 'No transactions recorded, yet.';
return message.channel.send(
new Discord.MessageEmbed()
.setTitle(`Transactions for ${target.tag}`)
.setColor(0x00AE86)
.setThumbnail(target.displayAvatarURL())
.setDescription(transactionlist)
.setFooter(`Page ${page} of ${total}`)
);
}
});
// gambling module
client.on('message', async message => {
//check if bot running
if (!running) return;
//if the sender is a bot ignore
if (message.author.bot) return;
//mkae sure message is not in DM