-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
1560 lines (1540 loc) · 61.7 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const fs = require("fs");
const Discord = require("discord.js");
const client = new Discord.Client();
const Helper = require("./helper-commands.js");
const EvilEval = require("./evil-eval.js");
const WorldGenerator = require("./generate-ascii-world.js");
const Token = require("./secret_stuff.json");
const words = require("./items.json");
const commands = require("./command-list.json");
const botinfo = require("./about.json");
const userData = require("./users.json");
const marketData = require("./market-items.json");
const robberies = require("./rob-state.json");
const houseData = require("./house.json");
const thumbs_up = "👍";
const thumbs_down = "👎";
const ok = "👌";
const left = "⬅";
const right = "➡";
const up = "🔼";
const down = "🔽";
const tree = "🌳";
const selected = "▶";
const unselected = "⬛";
const DemoCoinVerification = "🤔";
const colour = 0x00BCD4;
const maxItemsPerPage = 10;
const day = 24 * 60 * 60 * 1000;
const DemoCoinID = "432014777724698625";
const BCBWperDemoCoin = 1000;
const robRate = 10; // BCBW per second
const withdrawFee = 0.05;
const ConvertChannelID = "433441820102361110";
const DiscowID = "427609586032443392";
const CowBitperBCBW = 2;
const CowBotID = "427890474708238339";
const pageTypes = {
speller: {
name: "speller",
list: words,
onselect(word, channel) {
channel.send(`"${word}" is spelled \`${word.toUpperCase().split("").join("-")}\``);
}
},
commandList: {
name: "command list",
list: Object.keys(commands).map(c => `\`${c}\``),
onselect(command, channel, setTitle, otherStuff) {
setTitle(`**${command}**`);
return commands[command.slice(1, -1)].replace(/TREE/g, tree);
}
},
market: {
name: "market",
list: Object.keys(marketData).filter(i => marketData[i].buyable),
onselect(name, channel, setTitle, otherStuff) {
let item = marketData[name];
setTitle(item.emoji + " " + name);
questionAwaits[otherStuff.reactor.id] = {
type: "marketBuy",
args: name
};
return `${item.description}\n\nPrice: **\`${item.price}\`** bitcoin but worse`
+ `\nHow many do you want to buy? (\`cancel\` to cancel)`;
}
},
profiles: {
name: "profile list",
get list() {
return Object.values(userData).map(u => u.name).filter(uname => uname !== "<@undefined>");
},
onselect(username, channel, setTitle) {
let userID;
for (userID in userData) if (userData[userID].name === username) break;
setTitle(`${username}'s profile`);
return Helper.getProfile(userData[userID], marketData);
}
},
customEmojis: {
name: "custom emoji list",
list: [],
onselect(emoji, channel, setTitle, otherStuff) {
emoji = channel.guild.emojis.get(/<a?:.+?:([0-9]+)>/.exec(emoji)[1]);
setTitle(`<${emoji.animated ? "a" : ""}:${emoji.identifier}>`)
otherStuff.embed.addField("animated?", emoji.animated, true);
otherStuff.embed.addField("creation time", emoji.createdAt.toISOString(), true);
otherStuff.embed.addField("creation timestamp", emoji.createdTimestamp, true);
otherStuff.embed.addField("ID", emoji.id, true);
otherStuff.embed.addField("identifier", `\`${emoji.identifier}\``, true);
otherStuff.embed.addField("managed by external service?", emoji.managed, true);
otherStuff.embed.addField("requires colons?", emoji.requiresColons, true);
otherStuff.embed.addField("URL", emoji.url, true);
return "";
}
}
};
const questionResponseResponders = {
howRU(msg, args) {
let same = /\b(same|agree|also|too)\b/i.test(msg.content),
bad = same && args === "bad" || /\b(bad|sad|mad|unhappy|horrible)\b/i.test(msg.content),
ok = same && args === "ok" || /\b(ok|meh|idk|eh+)\b/i.test(msg.content),
good = same && args === "good" || /\b(good|great|happy|excited)\b/i.test(msg.content);
if (bad) {
if (args === "bad") Helper.permaSend(msg, "we can feel bad together!");
else Helper.permaSend(msg, "oh i'm very sorry to hear that");
} else if (ok) {
if (args === "ok") Helper.permaSend(msg, "good to know");
else Helper.permaSend(msg, "that's ok too");
} else if (good) {
if (args === "good") Helper.permaSend(msg, "yay we can be the happy group");
else Helper.permaSend(msg, "that's good!");
} else {
return false;
}
return true;
},
marketBuy(msg, name) {
let quantity = Math.abs(Math.round(+msg));
if (!isNaN(quantity)) {
let item = marketData[name],
totalCost = quantity * item.price;
prepareUser(msg.author.id);
if (totalCost > userData[msg.author.id].money) {
Helper.tempReply(msg, `**${userData[msg.author.id].name}** you don't have enough bitcoin but worse :/`);
msg.react(thumbs_down);
} else {
userData[msg.author.id].money -= totalCost;
prepareUserForItem(msg.author.id, name);
userData[msg.author.id].inventory[name] += quantity;
updateUserData();
Helper.tempReply(msg, `**${userData[msg.author.id].name}** thank you for your purchase.\n`
+ `you bought ${marketData[name].emoji} x${quantity} (${name}) for \`${totalCost}\` bitcoin but worse`);
msg.react(ok);
}
}
else if (msg.content.toLowerCase() === "cancel" || msg.content.toLowerCase() === "nvm") msg.react(ok);
else return false;
return true;
},
game(msg, args, questionAwait) {
if (args.purchaseHint) {
if (msg.content[0].toLowerCase() === "y") {
if (userData[msg.author.id].money < 50) {
msg.react(thumbs_down);
Helper.tempReply(msg, 1000, `${args.username}, not enough money!`);
} else {
args.hinted.push(args.purchaseHint);
userData[msg.author.id].money -= 50;
userData[msg.author.id].stats.hintPurchases++;
Helper.tempReply(msg, 1000, `${args.username}, purchased! :)`);
updateUserData();
msg.react(ok);
}
} else {
Helper.tempReply(msg, 1000, `${args.username}, canceled purchase! :)`);
msg.react(ok);
}
args.purchaseHint = false;
} else if (args.started) {
let hint = /^hint *([0-9]+)\b/i.exec(msg.content);
if (hint) {
hint = +hint[1];
if (hint > args.word.length || hint < 1) {
msg.react(thumbs_down);
Helper.tempReply(msg, 1000, `${args.username}, the letter is out of range`);
} else if (~args.hinted.indexOf(hint)) {
msg.react(thumbs_down);
Helper.tempReply(msg, 1000, `${args.username}, i already gave you the hint!`);
} else {
Helper.tempReply(msg, `${args.username}, purchase letter #${hint} for **\`50\`** bitcoin but worse? (y/n)`);
args.purchaseHint = hint;
}
} else {
args.tries++;
if (~msg.content.toLowerCase().indexOf(args.word)) {
let reward = args.word.length * 53;
userData[msg.author.id].money += reward;
userData[msg.author.id].stats.timesWonGame++;
Helper.tempReply(msg, `${args.username} just won **\`${reward}\`** bitcoin but worse!`);
questionAwait.dontAutoKill = false;
} else if (msg.content.toLowerCase() === "cancel") {
Helper.tempReply(msg, `cancel game. hints and penalties were not refunded. the word was **${args.word}**`);
questionAwait.dontAutoKill = false;
args.tries--;
} else if (args.tries >= 5 || userData[msg.author.id].money < 50) {
userData[msg.author.id].stats.timesLostGame++;
Helper.tempReply(msg, `${args.username} lost. the word was **${args.word}**`);
questionAwait.dontAutoKill = false;
} else {
userData[msg.author.id].money -= 50;
Helper.tempReply(msg, 1000, `${args.username}, nope! **\`50\`** bitcoin but worse penalty!`);
}
updateUserData();
}
} else {
prepareUser(msg.author.id);
args.word = words[Math.floor(Math.random() * words.length)];
args.hinted = [];
args.started = true;
args.purchaseHint = false;
args.username = `**${userData[msg.author.id].name}**`;
args.tries = 0;
msg.react(ok);
}
let content = `**GAME** ${args.tries} out of 5 tries\nPlayer: <@${msg.author.id}>`
+ "\nTens digit not displayed:```\n"
+ args.word.split("").map((l, i) => !questionAwait.dontAutoKill || ~args.hinted.indexOf(i + 1) ? l : "_").join(" ")
+ "\n" + args.word.split("").map((l, i) => (i + 1) % 10).join(" ")
+ "```\nTo buy a hint: `hint [nth letter, 1-indexed]` (eg `hint 3` for the third letter)"
+ "\n`cancel` to end game.";
// + "\nDEBUG:```" + `
// word:${args.word}
// hints:${JSON.stringify(args.hinted)}
// started:${args.started}
// purchasing hint:${args.purchaseHint}
// not stopping:${questionAwait.dontAutoKill}
// ` + "```";
args.msg.edit(content);
return true;
},
robbery(msg, args, questionAwait) {
if (!robberies[msg.author.id]) {
questionAwait.dontAutoKill = false;
return false;
}
let run = /\brun\b/i.test(msg.content);
if (run || /\bmy *progress\b/i.test(msg.content)) {
let stolenMoney = Math.floor((Date.now() - args.startTime - 5000) * robRate / 1000);
if (stolenMoney < 0) stolenMoney = 0;
if (args.bank) {
let totalBankMoney = Object.values(userData).map(u => u.bankMoney)
.reduce((a, b) => a + b);
stolenMoney = Math.min(stolenMoney, totalBankMoney);
} else {
stolenMoney = Math.min(stolenMoney, userData[args.victim].money)
}
if (run) {
userData[msg.author.id].lastRobbery = Date.now();
if (args.bank) {
let stealDistribution = {},
peopleWithBankMoney = Object.keys(userData).filter(u => userData[u].bankMoney),
done = false,
moneyToDistribute = stolenMoney,
extraMoney = stolenMoney % peopleWithBankMoney.length;
while (!done) {
let allOK = true,
moneyPerUser = Math.floor(moneyToDistribute / peopleWithBankMoney.length); // money can disappear through rounding
for (let i = 0; i < peopleWithBankMoney.length; i++) {
let u = peopleWithBankMoney[i];
if (moneyPerUser > userData[u].bankMoney) {
allOK = false;
stealDistribution[u] = userData[u].bankMoney;
moneyToDistribute -= userData[u].bankMoney;
peopleWithBankMoney.splice(i--, 1);
} else {
stealDistribution[u] = moneyPerUser;
}
}
if (allOK) done = true;
}
let DEBUG_STRING = `DEBUG. total stolen: ${stolenMoney}`
Object.keys(stealDistribution).map(u => {
DEBUG_STRING += `\n${userData[u].name} lost ${stealDistribution[u]} (orig: ${userData[u].bankMoney})`;
userData[u].bankMoney -= stealDistribution[u];
userData[u].stats.moneyLostFromRobbing += stealDistribution[u];
});
Helper.tempReply(msg, `**${userData[msg.author.id].name}** successfully `
+ `robbed **\`${stolenMoney}\`** bitcoin but worse from **__MOOFY BANK SERVICES__**`);
Helper.tempReply(msg, DEBUG_STRING);
} else {
userData[args.victim].money -= stolenMoney;
userData[args.victim].stats.moneyLostFromRobbing += stolenMoney;
Helper.tempReply(msg, `**${userData[msg.author.id].name}** successfully `
+ `robbed **\`${stolenMoney}\`** bitcoin but worse from **${userData[args.victim].name}**`);
}
userData[msg.author.id].money += stolenMoney;
userData[msg.author.id].stats.moneyFromRobbing += stolenMoney;
updateUserData();
msg.react(ok);
delete robberies[msg.author.id];
updateRobState();
questionAwait.dontAutoKill = false;
} else {
msg.react(ok);
Helper.tempReply(msg, `**${userData[msg.author.id].name}**, you have stolen `
+ `**\`${stolenMoney}\`** bitcoin but worse so far. type \`run\` to escape now`);
}
return true;
}
return false;
}
};
let paginations = [],
paginationData = {},
externalEchoChannel = null,
reactTarget = null,
emojiInfos = {},
scheduledUserDataUpdate = null,
questionAwaits = {},
exchanges = {},
scheduledRobStateUpdate = null,
ConvertChannel = null,
silenceTimeout = null;
const latestUserVersion = 20;
function prepareUser(id) {
if (typeof id !== "string") id = id.toString();
if (!userData[id]) userData[id] = {v: 0};
if (userData[id].v === latestUserVersion) return;
switch (userData[id].v) {
case 0:
userData[id].money = 0;
userData[id].stats = {};
userData[id].joined = Date.now();
userData[id].name = `<@${id}>`;
case 1:
userData[id].inventory = {};
case 2:
userData[id].lastDaily = 0;
userData[id].dailyStreak = 0;
case 3:
userData[id].stats.timesMined = 0;
userData[id].lastMine = 0;
case 4:
userData[id].stats.timesWonGame = 0;
userData[id].stats.timesLostGame = 0;
userData[id].stats.hintPurchases = 0;
// me trying to figure out fetchUser before I found out the problem wasn't here
case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13:
if (userData[id].name && ~userData[id].name.indexOf("@")) {
let mentionRegex = /<@!?([0-9]+)>/.exec(userData[id].name);
if (mentionRegex) {
client.fetchUser(mentionRegex[1]).then(user => {
userData[id].name = user.username;
});
} else {
userData[id].name = userData[id].name.replace(/@/g, "[at]");
}
}
case 14:
userData[id].stats.timesRobbed = 0;
userData[id].stats.timesGotRobbed = 0;
userData[id].stats.moneyFromRobbing = 0;
userData[id].stats.moneyLostFromRobbing = 0;
userData[id].stats.timesGotCaught = 0;
userData[id].stats.timesCaughtRobber = 0;
case 15:
userData[id].stats.coffeeConsumed = 0;
if (userData[id].stats.moneyLostFromRobbing < 0)
userData[id].stats.moneyLostFromRobbing *= -1;
case 16:
userData[id].bankMoney = 0;
case 17:
userData[id].bannedFromBank = false;
userData[id].stats.timesAttackedRobber = 0;
case 18:
userData[id].lastRobbery = 0;
if (userData[id].stats.moneyLostFromRobbing < 0)
userData[id].stats.moneyLostFromRobbing *= -1;
case 19:
userData[id].inHouse = false;
userData[id].houseFeatures = {};
userData[id].houseSecurityLvl = 0;
userData[id].robHelpLvl = 0;
}
userData[id].v = latestUserVersion;
updateUserData();
}
function prepareUserForItem(userID, itemName, inventory = "inventory") {
if (userData[userID][inventory][itemName] === undefined)
userData[userID][inventory][itemName] = 0;
}
function updateUserData() {
if (scheduledUserDataUpdate !== null) clearTimeout(scheduledUserDataUpdate);
scheduledUserDataUpdate = setTimeout(() => {
scheduledUserDataUpdate = null;
fs.writeFile("./users.json", JSON.stringify(userData), () => {});
}, 100);
}
function updateRobState() {
if (scheduledRobStateUpdate !== null) clearTimeout(scheduledRobStateUpdate);
scheduledRobStateUpdate = setTimeout(() => {
scheduledRobStateUpdate = null;
fs.writeFile("./rob-state.json", JSON.stringify(robberies), () => {});
}, 100);
}
function setGame() {
client.user.setPresence({
game: {
name: "you",
type: 3
}
});
}
const DESIRED_EXCHANGE_RATE = 0.01; // universal:BCBW
const MAXIMUM_EXCHANGE_RATE = 1; // universal:BCBW
const UNIVERSAL_TOTAL = 100000; // universal?
const NORMAL_TOTAL = 10000000; // BCBW?
function calculateUniversalExchangeRate() {
let total = 0; // BCBW
let govMoney = UNIVERSAL_TOTAL / MAXIMUM_EXCHANGE_RATE; // ???
Object.values(userData).forEach(u => total += u.money + u.bankMoney);
// return 1 / (govMoney + total) * UNIVERSAL_TOTAL;
return 1 / (govMoney + (total * UNIVERSAL_TOTAL) / (DESIRED_EXCHANGE_RATE * NORMAL_TOTAL)) * UNIVERSAL_TOTAL;
}
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
Object.keys(userData).map(id => userData[id].v < latestUserVersion ? prepareUser(id) : 0);
ConvertChannel = client.channels.get(ConvertChannelID);
setGame();
});
client.on("message", msg => {
let message = msg.content,
channel = msg.channel,
userID = msg.author.id;
if (userID === client.user.id) return;
if (silenceTimeout !== null) return;
if (questionAwaits[userID]) {
let valid = questionResponseResponders[questionAwaits[userID].type](msg, questionAwaits[userID].args, questionAwaits[userID]);
if (!questionAwaits[userID].dontAutoKill) delete questionAwaits[userID];
if (valid) return;
} else if (robberies[userID]) {
questionAwaits[userID] = {
type: "robbery",
args: robberies[userID],
dontAutoKill: true
};
}
let sendOK = true;
prepareUser(userID);
if (~botinfo.universalers.indexOf(userID) && msg.mentions.members.has(client.user.id)) {
if (msg.embeds[0]) {
let embed = msg.embeds[0];
if (embed.title === "convert") {
try {
let exec = /<@!?([0-9]+)> *([0-9.\-]+)/i.exec(embed.description),
user = exec[1],
amount = +exec[2];
prepareUser(user);
if (isNaN(amount) || amount < 0)
throw new Error("i don't like that \"positive number\" you have there");
else {
msg.react(ok);
const conversionRate = calculateUniversalExchangeRate();
userData[user].money += Math.floor(amount / conversionRate);
updateUserData();
}
} catch (e) {
Helper.permaSend(msg, "```" + e.toString() + "```");
sendOK = false;
msg.react(thumbs_down);
}
return;
}
}
}
if (message.slice(-20) === "REPLACE COLON PLEASE") {
message = message.replace(/COLON/g, ":");
}
if (/\bh(?:(?:4|a)t|8)(?!s)(?=\w)/i.test(message)) {
let hat = {h: "l", H: "L", a: "o", A: "O", t: "v", T: "V", 4: "0", 8: "0\\/"};
Helper.permaSend(msg, `hey hey hey <@${userID}> don't be so negative! try this:`
+ "```" + message.replace(
/(h(?:(?:4|a)t|8))r(e|3)d/gi,
(m, c1, c2) => c1.split("").map(l => hat[l]).join("")
+ (c2 === "3" ? "3" : c2.toUpperCase() === c2 ? "E" : "e")
).replace(
/\b(h(?:(?:4|a)t|8))(?!s)(?=\w)/gi,
(m, c1) => c1.split("").map(l => hat[l]).join("")
) + "```");
sendOK = false;
msg.react(thumbs_down);
} else if (message.slice(0, 6).toLowerCase() === "moofy:") {
let command = message.toLowerCase().split(/ +/).slice(1).join(" "),
conclusive = false,
item;
for (let security in houseData) {
if (houseData[security].command === command) {
conclusive = true;
item = security;
}
}
if (conclusive) {
prepareUserForItem(userID, item, "houseFeatures");
if (userData[userID].houseFeatures[item] >= houseData[item].maximum) {
Helper.tempReply(msg, `**${userData[userID].name}** you have too many ${item}`);
sendOK = false;
msg.react(thumbs_down);
} else if (userData[userID].money < houseData[item].cost) {
Helper.tempReply(msg, `**${userData[userID].name}** you don't have enough bitcoin but worse`);
sendOK = false;
msg.react(thumbs_down);
} else {
userData[userID].money -= houseData[item].cost;
userData[userID].houseFeatures[item]++;
if (houseData[item].security !== undefined)
userData[userID].houseSecurityLvl += houseData[item].security;
else
userData[userID].robHelpLvl += houseData[item].assist;
updateUserData();
Helper.tempReply(msg, `**${userData[userID].name}** purchased 1x ${item} for **\`${houseData[item].cost}\`** bitcoin but worse`);
}
} else if (command === "house enter") {
if (userData[userID].inHouse) {
Helper.tempReply(msg, `**${userData[userID].name}** you're already in your house silly`);
sendOK = false;
msg.react(thumbs_down);
} else if (!userData[userID].houseFeatures.house) {
Helper.tempReply(msg, `**${userData[userID].name}** you don't have a house!`);
sendOK = false;
msg.react(thumbs_down);
} else {
userData[userID].inHouse = true;
updateUserData();
}
} else if (command === "house exit") {
if (!userData[userID].inHouse) {
Helper.tempReply(msg, `**${userData[userID].name}** you're already outside your house silly`);
sendOK = false;
msg.react(thumbs_down);
} else {
userData[userID].inHouse = false;
updateUserData();
}
} else if (command === "my house") {
msg.author.createDM().then(channel => {
channel.send({
embed: {
color: colour,
title: "Your house",
description: `**Total security**: ${userData[userID].houseSecurityLvl}`
+ `\n**Total robber assist**: ${userData[userID].robHelpLvl}`
+ `\nYou are **${userData[userID].inHouse ? "" : "not "}in** your house.`,
fields: Object.keys(userData[userID].houseFeatures).map(f => ({
name: f,
value: userData[userID].houseFeatures[f],
inline: true
}))
}
});
});
} else if (command.slice(0, 13) === "get universal") {
let total = 0;
Object.values(userData).forEach(u => total += u.money + u.bankMoney);
// to universal = given amount / (government money + total) * universal total
// universal total is 1 million (1000000)
// maydoh recommends:
// a universal total of 10000
// and government money of 10000
const conversionRate = calculateUniversalExchangeRate();
if (command.length === 13) {
Helper.permaSend(msg, `total BCBW: \`${total}\`. \`1\` BCBW = \`${conversionRate}\` universal`);
} else {
let amount = +command.slice(13).trim();
Helper.permaSend(msg, `\`${amount}\` BCBW = \`${amount * conversionRate}\` universal.`
+ `\n\`${amount}\` universal = \`${amount / conversionRate}\` BCBW`);
}
} else if (command.slice(0, 12) === "feature info") {
let featureName = command.slice(12).trim(),
feature = houseData[featureName];
if (feature) {
Helper.tempReply(msg, {
embed: {
title: featureName,
fields: [
{name: "cost", value: feature.cost, inline: true},
{name: "maximum", value: feature.maximum, inline: true},
feature.security !== undefined
? {name: "security", value: feature.security, inline: true}
: {name: "assist", value: feature.assist, inline: true}
],
color: colour
}
})
} else {
Helper.tempReply(msg, `**${userData[userID].name}** that's not a name of a feature`);
sendOK = false;
msg.react(thumbs_down);
}
} else if (command === "gen world of emoji") {
Helper.permaSend(msg, WorldGenerator(10, 10, {
tableSize: 512,
scale: 10,
biomeChars: {
OCEAN: "🌊",
MOUNTAIN: "⛰",
PLAINS: "☘",
DESERT: "🏜",
FOREST: "🌳",
VILLAGE: "🏘"
},
villageChance: 15
}).map(a => a.join("")).join("\n"));
} else if (command === "gen world") {
Helper.permaSend(msg, "```css\n" + WorldGenerator(20, 20, {
tableSize: 512,
scale: 20,
biomeChars: {
OCEAN: "~",
MOUNTAIN: "^",
PLAINS: ",",
DESERT: ".",
FOREST: ";",
VILLAGE: "V"
},
villageChance: 30
}).map(a => a.join(" ")).join("\n") + "```");
} else {
Helper.tempReply(msg, {
embed: {
color: colour,
title: "Property system",
description: Object.keys(houseData).map(f => {
return `\`moofy: ${houseData[f].command}\` - buys a **${f}** (${houseData[f].cost} bcbw, ${houseData[f].maximum} max)`;
}).join("\n")
+ `\n\`moofy: house enter\` - enters your house`
+ `\n\`moofy: house exit\` - exits your house`
+ `\n\`moofy: my house\` - DMs information about your house to you`
+ `\n\`moofy: feature info [feature name]\` - gives more information about the feature`
}
});
}
} else if (userID !== DiscowID && userID !== CowBotID && (msg.mentions.users.has(client.user.id) || /^moofy,? */i.test(message))) {
let moreInfo = /\bt(?:ell)? *me? *(?:more)? *a(?:bout)? *([a-z]+)(?: *#?([0-9]+))?/i.exec(message);
if (moreInfo) {
let query = moreInfo[1].trim().toLowerCase(),
resultIndex = +moreInfo[2] || 1,
results = Object.keys(commands).filter(c => ~c.toLowerCase().indexOf(query));
if (results.length === 0) {
Helper.tempReply(msg, `couldn't find the command you were looking for (try \`@moofy-bot your commands\` for the full list)`);
sendOK = false;
msg.react(thumbs_down);
} else {
if (resultIndex > results.length) resultIndex = results.length;
let command = results[resultIndex - 1];
Helper.tempReply(msg, {
embed: {
title: `**\`${command}\`**`,
description: commands[command].replace(/TREE/g, tree)
+ `\n\nOther results (use \`@moofy-bot tell me more about ${query} #n\`):\n`
+ results.map((c, i) => `${i + 1}. \`${c}\``).join("\n"),
color: colour
}
});
}
} else if (/\b(help|((your|ur) *)?commands?|command *format)\b/i.test(message)) {
initPagination(msg, "commandList");
} else if (/\bwho\b/i.test(message)) {
let content = [];
Helper.tempReply(msg, {
embed: {
footer: {
text: `VARIANT: ${botinfo.variant}`
},
description: botinfo.description + `\n\nMy insides: ${botinfo.repo}\nSpam your server too: ${botinfo.invite}`,
title: `ABOUT ${botinfo.name}`,
color: colour,
url: botinfo.repo
}
});
} else if (/\bhow *(r|are) *(u|you)\b/i.test(message)) {
let feelings = ["good", "ok", "bad"],
feeling = feelings[Math.floor(Math.random() * feelings.length)];
Helper.permaSend(msg, `i'm feeling ${feeling}. and you?`)
questionAwaits[userID] = {
type: "howRU",
args: feeling
};
} else if (/\bmarket\b/i.test(message)) {
initPagination(msg, "market");
} else if (/\bGAME\b/.test(message)) {
Helper.permaSend(msg, "loading...").then(msg => {
msg.edit("say anything to start");
questionAwaits[userID] = {
type: "game",
args: {
msg: msg,
started: false
},
dontAutoKill: true
};
});
} else if (/\bGAME\b/i.test(message)) {
Helper.tempReply(msg, `NOT LOUD ENOUGH <@${userID}>`);
} else if (/\bprofiles\b/i.test(message)) {
initPagination(msg, "profiles");
} else if (/\bleader(?:board)?\b/i.test(message)) {
let peopleMoney = Object.values(userData).filter(u => u.money > 0)
.sort((a, b) => b.money - a.money);
if (peopleMoney.length) {
let digitLengths = peopleMoney[0].money.toString().length,
spaces = " ".repeat(digitLengths);
Helper.permaSend(msg, {
embed: {
color: colour,
title: "people with the most bitcoin but worse",
description: peopleMoney.map(u => `\`+${(spaces + u.money).slice(-digitLengths)}\` **${u.name}**`).join("\n")
}
});
}
} else if (/\bSHUT *UP\b/.test(message)) {
if (silenceTimeout !== null) clearTimeout(silenceTimeout);
Helper.tempReply(msg, `**MOOFY WILL NOW IGNORE COMMANDS FOR A SECOND**`);
silenceTimeout = setTimeout(() => {
silenceTimeout = null;
setGame();
}, 1000);
client.user.setPresence({
game: {
name: "no one",
type: "LISTENING"
}
});
} else {
let deleteRegex = /\bdelete *([0-9]+)\b/i.exec(message),
reactCustom = /\breact *<a?:.+?:([0-9]+)>/i.exec(message),
react = /\breact *([^\sa-z0-9]{1,2})/i.exec(message),
buy = /\bbuy *([0-9]+|max(?:imum)?) *(\S{1,2})/i.exec(message),
getProfile = /\bprofile *<@!?([0-9]+)>/i.exec(message);
if (deleteRegex) {
let amount = +deleteRegex[1];
if (amount > 100) {
Helper.tempReply(msg, `<@${userID}> due to technical limitations i can't delete more than 100`);
sendOK = false;
msg.react(thumbs_down);
} else if (Math.floor(Math.random() * 4)) {
Helper.tempReply(msg, `<@${userID}> nahhh`);
sendOK = false;
msg.react(thumbs_down);
} else {
channel.fetchMessages({limit: amount}).then(msgs => {
msgs.map(msg => {
if (msg.author.id === client.user.id) {
msg.delete();
} else {
msg.reactions.filter(r => r.me).map(r => r.remove());
}
});
});
sendOK = false;
}
} else if (reactCustom) {
try {
if (!reactTarget) throw new Error("which message?");
reactTarget.react(client.emojis.get(reactCustom[1])).catch(err => {
Helper.sendError(channel, err)
});
} catch (e) {
Helper.permaSend(msg, `<@${userID}> **\`\`\`${e.toString().toUpperCase()}\`\`\`**`);
sendOK = false;
}
} else if (react) {
try {
if (!reactTarget) throw new Error("which message?");
if (react[1] === thumbs_up || react[1] === thumbs_down)
throw new Error("don't dare you try to manipulate votes!");
reactTarget.react(react[1]).catch(err => {
Helper.sendError(channel, err)
});
} catch (e) {
Helper.permaSend(msg, `<@${userID}> **\`\`\`${e.toString().toUpperCase()}\`\`\`**`);
sendOK = false;
}
} else if (buy) {
let item = getItem(buy[2]), quantity;
if (buy[1][0] === "m") quantity = Math.floor(userData[userID].money / marketData[item].price);
else quantity = +buy[1];
if (!Helper.buy(msg, item, quantity, marketData[item], userID, userData[userID], updateUserData, prepareUserForItem)) {
sendOK = false;
msg.react(thumbs_down);
}
} else if (getProfile) {
let userDataEntry = userData[getProfile[1]];
Helper.permaSend(msg, {
embed: {
title: `${userDataEntry.name}'s profile`,
description: Helper.getProfile(userDataEntry, marketData),
color: colour
}
});
} else {
Helper.tempReply(msg, `<@${userID}> DON'T MENTION ME`);
sendOK = false;
}
}
} else if (/^pag(e|ination) *test\b/i.test(message)) {
initPagination(msg, "speller");
} else if (/^use *this *channel\b/i.test(message)) {
externalEchoChannel = channel;
} else if (/\bdumb\b/i.test(message) && /\bbot\b/i.test(message)) {
Helper.permaSend(msg, `DID I JUST HEAR "dumb" AND "bot" USED TOGETHER??!!??!11!?1/!?`);
sendOK = false;
msg.react(thumbs_down);
} else if (/^inspect *emoji\b/i.test(message)) {
let embed = new Discord.RichEmbed({
footer: {
text: `react to set emoji`
},
description: "awaiting reaction",
title: "emoji inspector",
color: colour
});
Helper.permaSend(msg, {
embed: embed
}).then(msg => {
emojiInfos[msg.id] = {
embed: embed,
msg: msg
};
});
} else if (/\bkeepInventory\b/i.test(message) && msg.author.username === "Gamepro5") {
Helper.permaSend(msg, `<@${userID}>` + " make sure you set `keepInventory` to `false` :)");
sendOK = false;
msg.react(thumbs_down);
} else if (/^my *daily\b/i.test(message)) {
let now = Date.now(),
timeSince = now - userData[userID].lastDaily,
addendum = "";
if (timeSince >= day) {
userData[userID].money += 500;
if (timeSince > day * 2 && userData[userID].lastDaily > 0) {
addendum = `\nrip, you lost your ${userData[userID].dailyStreak}-day streak`
userData[userID].dailyStreak = 0;
}
userData[userID].lastDaily = now;
userData[userID].dailyStreak++;
updateUserData();
Helper.tempReply(msg, `<@${userID}> good job! here's **\`500\`** bitcoin but worse for you :D\n`
+ `(${userData[userID].dailyStreak}-day streak!)` + addendum);
} else {
let lastDaily = new Date(userData[userID].lastDaily);
Helper.tempReply(msg, `<@${userID}> be patient! you last got your daily at `
+ `${(lastDaily.getHours() + 11) % 12 + 1}:${("0" + lastDaily.getMinutes()).slice(-2)} ${lastDaily.getHours() < 12 ? "a" : "p"}m`);
sendOK = false;
msg.react(thumbs_down);
}
} else if (/^i *want *to *mine\b/i.test(message)) {
let mineResult = Helper.mine(userData[userID], userID, updateUserData, prepareUserForItem);
Helper.tempReply(msg, mineResult.content);
if (mineResult.error) {
sendOK = false;
msg.react(thumbs_down);
}
} else if (userID === DemoCoinID) {
if (msg.embeds[0]) {
let embed = msg.embeds[0],
command = embed.title.trim().split(/\s+/);
if (command[0] === "convert") {
try {
let amount = +command[1],
user = /<@!?([0-9]+)>/.exec(embed.description)[1];
prepareUser(user);
if (isNaN(amount) || amount < 0)
throw new Error("i don't like that \"positive number\" you have there");
else {
msg.react(ok);
userData[user].money += Math.floor(amount * BCBWperDemoCoin);
updateUserData();
}
} catch (e) {
Helper.permaSend(msg, "```" + e.toString() + "```");
sendOK = false;
msg.react(thumbs_down);
}
} else {
sendOK = false;
}
} else {
sendOK = false;
}
} else if (/^HEY\b/.test(message)) {
Helper.tempReply(msg, `**${userData[userID].name}**, the \`HEY\` command is now deprecated. please use \`attack\``);
sendOK = false;
msg.react(thumbs_down);
} else if (/^my *bank *acc(?:ount)?\b/i.test(message)) {
if (userData[userID].inHouse) {
Helper.tempReply(msg, `**${userData[userID].name}**, the bank doesn't have a website. you have to leave your house and go there in person.`);
sendOK = false;
msg.react(thumbs_down);
} else if (userData[userID].bannedFromBank) {
Helper.tempReply(msg, `you were banned from the bank on ${new Date(userData[userID].bannedFromBank).toString()}`);
} else {
Helper.tempReply(msg, `you have **\`${userData[userID].bankMoney}\`** bitcoin but worse protected by MOOFY BANK SERVICES`);
}
} else if (/^my *progress\b/i.test(message)) {
Helper.tempReply(msg, `you aren't robbing right now. robbers: `
+ (Object.keys(robberies).map(id => `**${(userData[id] || {}).name}**`).join(", ") || "none"));
} else if (/^rob *(?:the|l')? *bank\b/i.test(message)) {
if (userData[userID].inHouse) {
Helper.tempReply(msg, `**${userData[userID].name}**, the bank doesn't have a website. you have to leave your house and go there in person.`);
sendOK = false;
msg.react(thumbs_down);
} else if (robberies[userID]) {
sendOK = false;
msg.react(thumbs_down);
Helper.tempReply(msg, `**${userData[userID].name}**, you're a bit busy with another robbery at the moment.`);
} else if (Date.now() - userData[userID].lastRobbery < 1800000) {
sendOK = false;
msg.react(thumbs_down);
Helper.tempReply(msg, `**${userData[userID].name}**, you're still tired from your last robbery`);
} else {
if (channel.type !== "dm") {
robberies[userID] = {
bank: true,
startTime: Date.now()
};
questionAwaits[userID] = {
type: "robbery",
args: robberies[userID],
dontAutoKill: true
};
userData[msg.author.id].stats.timesRobbed++;
updateUserData();
updateRobState();
Helper.permaSend(msg, `**${userData[userID].name.toUpperCase()}** IS STEALING `
+ `FROM THE ***__MOOFY BANK SERVICES__***. TYPE **\`ATTACK\`**`
+ ` TO ATTACK THE ROBBER.\nThere is no backing out now. Type \`my progress\` to`
+ ` see how much money you stole, and \`run\` to escape with your BCBW.`
+ `\n\n@everyone you might want to wake up`);
} else {
sendOK = false;
msg.react(thumbs_down);
Helper.tempReply(msg, `**${userData[userID].name}**, **${userData[victim].name}** doesn't live here!`);
}
}
} else if (/^idea *(for|4)? *moofy:/i.test(message)) {
let idea = "\n".repeat(3) + "@" + msg.author.tag + " SAID:\n" + message.slice(message.indexOf(":") + 1).trim();
fs.readFile('./ideas.txt', (err, data) => {
fs.writeFile('./ideas.txt', data + idea, () => {});
});
Helper.tempReply(msg, `<@${userID}> saved`);
} else if (/^post *embed:/i.test(message)) {
let json = message.slice(message.indexOf(":") + 1).replace(/convert/gi, "");
try {
json = JSON.parse(json);
if (json.timestamp) json.timestamp = new Date(json.timestamp);
channel.send("as requested:", {embed: json}).catch(err => {
Helper.sendError(channel, err);
});
} catch (e) {
sendOK = false;
msg.react(thumbs_down);
Helper.tempReply(msg, `there was a problem:\`\`\`\n${e}\`\`\`see https://discord.js.org/#/docs/main/stable/class/RichEmbed for more info`);
}
} else if (/^call *police\b/i.test(message)) {
let personRobberies = Object.keys(robberies).filter(r => userData[r].inHouse);
if (personRobberies.length > 0) {
personRobberies.map(r => {
let fine = userData[r] > 12000 ? 4000 : Math.floor(userData[r].money / 3);
userData[r].money -= fine;
userData[userID].money += fine;
userData[r].timesGotCaught++;
userData[userID].timesCaughtRobber++;
updateUserData();
Helper.permaSend(msg, `**${userData[r].name}** caught! they will be forced to `
+ `return the stolen money and pay **\`${fine}\`** bitcoin but worse `
+ `to **${userData[userID].name}** for their service.`);
delete robberies[r];
});
updateRobState();
} else {
let objects = ["bird", "bee", "pickle", "car", "performer", "clock", "pencil",
"tree", "plane", "hallucination", "superhero who forgot to put on their jacket this morning",
"dictator", "cloud of poison gas", "cat"];
Helper.tempReply(msg, `**${userData[userID].name}**, there aren't any ongoing house robberies. that was probably a `
+ objects[Math.floor(Math.random() * objects.length)]);
sendOK = false;
msg.react(thumbs_down);
}
} else if (/^what *('?re|are) *(the)? *emojis? *(on)? *(this)? *server\b/i.test(message)) {
pageTypes.customEmojis.list = msg.guild.emojis.map(e => `<${e.animated ? "a" : ""}:${e.identifier}>`);
initPagination(msg, "customEmojis");
} else if (message.slice(0, 11) === "eval: ```js") {
if (~botinfo.makers.indexOf(userID)) {
Helper.permaSend(msg, EvilEval.EVAL(message.slice(11, -3), msg));
} else {
Helper.tempReply(msg, `**${userData[userID].name}**, you do not have the permissions`);
}
} else {
let echo = /^echo?([cxseu]*):([^]+)/im.exec(message),
ofNotHaveRegex = /\b(could|might|should|will|would)(?:'?ve| +have)\b/gi,
ofNotHave = ofNotHaveRegex.exec(message),
random = /^(actually *)?(?:pick *)?(?:a *)?rand(?:om)? *num(?:ber)? *(?:d'|from|between)? *([0-9]+) *(?:-|to|t'|&|and|n')? *([0-9]+)/i.exec(message),
getMoney = /^(my|<@!?([0-9]+)>(?: *'?s)?) *(?:money|bcbw)\b/i.exec(message),
setName = /^my *name *(?:'s|is) +(.+)/i.exec(message),
giveMoney = /^give *<@!?([0-9]+)> *([0-9]+) *(?:money|bcbw)\b/i.exec(message),
getInventory = /^(my|<@!?([0-9]+)>(?: *'?s)?) *inv(?:entory)?\b/i.exec(message),
convertMoney = /^(?:exchange|convert) *([0-9]+) *bcbw *(?:to|2) *([a-z]+)\b/i.exec(message),
rob = /^(?:rob|steal) *(?:from|d')? *<@!?([0-9]+)>/i.exec(message),
consume = /^(?:consume|eat|drink) *(\S{1,2})/i.exec(message),