-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
2010 lines (1989 loc) · 95.5 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const dotenv = require("dotenv");
dotenv.config();
const discord = require("discord.js");
const db = require("./db.js");
const songbird = require("./songbird.js");
const util = require("./util.js");
const { fetch } = require("cross-fetch");
const client = new discord.Client({
intents: [discord.GatewayIntentBits.Guilds, discord.GatewayIntentBits.GuildMembers, discord.GatewayIntentBits.GuildMessages]
});
const ADMINS = ["239770148305764352", "288612712680914954", "875942059503149066", "600071769721929746", "1074092955943571497", "486380942911471617"];
//mods too
const TEAM = [...ADMINS];
const DOMAIN_END = 1694029371; //september 7th, 2023 00:00 UTC
const MIN_SGB = 0.25;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
//23 1/2 hours
const CLAIM_FREQ = db.CLAIM_FREQ;
const MAX_CLAIMS_PER_MONTH = 11111;
const HOLDING_REQUIREMENT = 2000;
let historic_data_cache;
let liqudity_cache;
let sgb_price_cache;
let pptr_cache;
let burned_cache;
client.once("ready", async (info) => {
console.log("Ready! as " + info.user.tag);
//set price status
async function set_price_status() {
let price;
try {
historic_data_cache = await songbird.get_historic();
price = (await songbird.get_price()).base_token_price_usd.slice(0, 10);
//also get sgb price
sgb_price_cache = await songbird.get_coin_price("songbird");
//liquidity
liqudity_cache = await songbird.get_liquidity_blaze(Number(price), sgb_price_cache);
} catch (e) {
console.log(e);
return;
}
client.user.setPresence({
activities: [
{
//name: "Astral Price: $" + price,
name: "XAC Price",
type: 3,
}
],
status: "online",
});
//change nickname
try {
let astral_guild = client.guilds.cache.get("1000985457393422367");
let self_member = await astral_guild.members.fetchMe();
await self_member.setNickname("$"+price);
} catch (e) {
console.log(e);
console.log("Failed to change username!");
}
}
set_price_status();
setInterval(set_price_status, 25 * 60 * 1000);
//start milestone check
async function send_announcement(text) {
client.channels.cache.get("1103087597875634257").send(text);
}
setTimeout(async () => {
await db.milestone_check(send_announcement);
}, 7500);
setInterval(async () => {
await db.milestone_check(send_announcement);
}, 30 * 60 * 1000);
async function set_pptr_cache() {
let token_resp = await (await fetch("https://songbird-explorer.flare.network/api?module=account&action=tokentx&address=0x93CA88Ee506096816414078664641C07aF731026")).json();
pptr_cache = token_resp.result.filter((t) => t.input.startsWith("0xd2b7f857")); //setPixel (todo: support setPixelBatch)
}
set_pptr_cache();
setInterval(set_pptr_cache, 4 * 60 * 1000);
burned_cache = await db.calculate_burned();
setInterval(async () => burned_cache = await db.calculate_burned(), 12 * 60 * 60 * 1000);
});
async function add_achievement(user_id, achievement_id, cached_user, member) {
//add_achievement_db returns false if user already has the acheivement
if (await db.add_achievement_db(user_id, achievement_id, cached_user)) {
const achievement_info = db.ACHIEVEMENTS[achievement_id];
//pay prize from team's collective tipping wallet to the user's tipping wallet
let user_tipbot_address = songbird.get_tipbot_address(user_id);
let tx = false;
if (achievement_info.prize > 0) {
tx = await songbird.send_astral(user_tipbot_address, achievement_info.prize);
}
//send message in notifications
let astral_guild = client.guilds.cache.get("1000985457393422367");
await astral_guild.channels.fetch();
//notifications: 1103087597875634257
let achievement_notif_embed = new discord.EmbedBuilder();
achievement_notif_embed.setTitle("Achievement Earned!");
achievement_notif_embed.setColor("#30d613");
achievement_notif_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1212874280430215249/Medal.png?ex=65f36c32&is=65e0f732&hm=6c53aaec349530422678d6bd5a2ab020c16761b8bf9566b8d7361c3759cce539&");
let notif_description = `Congratulations! <@${user_id}> has earned the achievement **"${achievement_info.name}" (${achievement_info.description})**`;
if (achievement_info.prize > 0) {
notif_description += `\nPrize: ${achievement_info.prize} <:XAC:1228104930464895106>\n[View Tx](https://songbird-explorer.flare.network/tx/${tx}) (sent to tipbot wallet)`;
}
achievement_notif_embed.setDescription(notif_description);
achievement_notif_embed.setFooter({ text: "Do /unlocked_achievements to see a list of your unlocked achievements" });
//add role if any
if (achievement_info.role) {
member.roles.add(achievement_info.role);
achievement_notif_embed.addFields([
{
name: "Role Awarded",
value: `<@&${achievement_info.role}>`
}
]);
}
await astral_guild.channels.cache.get("1103087597875634257").send({ content: `<@${user_id}> completed an achievement :trophy:`, embeds: [achievement_notif_embed] });
return true;
}
return false;
}
let message_xp_cooldown_cache = {};
const MESSAGE_XP_COOLDOWN = 20 * 1000;
client.on("messageCreate", async (message) => {
//ignore message if not from xac server
if (message.guildId !== "1000985457393422367") return;
//Count a max of 1 message every 20 seconds toward the achievement (anti-spam)
if (message_xp_cooldown_cache[message.author.id]+MESSAGE_XP_COOLDOWN < Date.now() || !message_xp_cooldown_cache[message.author.id]) {
message_xp_cooldown_cache[message.author.id] = Date.now();
let user_info = await db.get_user(message.author.id);
//don't do anything if not registered
if (user_info) {
await db.increment_message_achievement_info(message.author.id);
//don't judge
switch (user_info.achievement_data.messages+1) {
case 30:
await add_achievement(message.author.id, "activity-1", user_info, message.member);
break;
case 100:
await add_achievement(message.author.id, "activity-2", user_info, message.member);
break;
case 500:
await add_achievement(message.author.id, "activity-3", user_info, message.member);
break;
case 1000:
await add_achievement(message.author.id, "activity-4", user_info, message.member);
break;
case 2500:
await add_achievement(message.author.id, "activity-5", user_info, message.member);
break;
case 5000:
await add_achievement(message.author.id, "activity-6", user_info, message.member);
break;
default:
//nothing
}
}
}
});
client.on("interactionCreate", async interaction => {
let command = interaction.commandName;
let params = interaction.options;
let user = interaction.user;
//
if (command === "help") {
await interaction.deferReply({ ephemeral: true });
let help_embed = new discord.EmbedBuilder();
help_embed.setTitle("Help");
help_embed.setColor("#08338e");
help_embed.setDescription("This bot is your friendly neighbourhood bot for all things Astral Credits! Programmed by [Prussia](https://prussia.dev/sample).");
help_embed.addFields([
{
name: "/help",
value: "Get a list of commands."
},
{
name: "/faucet",
value: "Use the monthly XAC faucet, and participate in the XAC distribution!"
},
{
name: "/price",
value: "Get XAC price info."
},
{
name: "/pools",
value: "Get information about all the pools XAC is tradable on."
},
{
name: "/next_claim",
value: "Check to see if your next faucet claim is ready."
},
{
name: "/faucet_stats",
value: "See some neat faucet metrics."
},
{
name: "/register",
value: "Register your address with the bot so admins can send you XAC more easily."
},
{
name: "/add_website",
value: "Link a website to your address, which will show up in any pixels you place in the XAC pixel billboard."
},
{
name: "/pixels",
value: "Get the link to the Pixel Planet dApp"
},
{
name: "/coinflip_pvp",
value: "Player vs player coinflip betting game"
},
{
name: "/coinflip_pvh",
value: "Player vs house coinflip betting game"
},
{
name: "/provably_fair_pvp",
value: "Player vs player coinflip betting game explanation"
},
{
name: "/provably_fair_pvh",
value: "Player vs house coinflip betting game explanation"
},
{
name: "/unlocked_achievements",
value: "See your unlocked achievements"
},
{
name: "/locked_achievements",
value: "See achievements you haven't unlocked yet"
},
{
name: "/claim_achievements",
value: "Manually claim certain achievements"
},
{
name: "/leaderboard",
value: "See the users with the most achievements"
},
]);
help_embed.setFooter({ text: "Made by prussia.dev" });
await interaction.member.fetch();
if (ADMINS.includes(user.id) || interaction.member.roles.cache.has("1001004354981077032") || interaction.member.roles.cache.has("1127728118006829136")) {
let admin_embed = new discord.EmbedBuilder();
admin_embed.setTitle("Admin Help");
admin_embed.addFields([
{
name: "/send",
value: "Admins can send XAC to discord users or addresses."
},
{
name: "/change_register",
value: "Admins can change a registered user's address."
},
{
name: "/view_addresses",
value: "View addresses of an user"
},
{
name: "/reverse_lookup",
value: "Find registered user from address"
},
{
name: "/remove_linked_website",
value: "Admins can remove a registered user's linked website, if they linked."
},
{
name: "/list_role",
value: "Utility function to get all the users of a role"
},
{
name: "/crawl",
value: "See connections between addresses"
},
{
name: "/crawl_shared_txs",
value: "See txs between addresses"
},
{
name: "/registered_count",
value: "Get a count of all registered users"
},
{
name: "/admin_balance",
value: "See balance of the admin tipping wallet"
}
]);
admin_embed.setFooter({ text: "\"The ships hung in the sky in much the same way that bricks don't.\" -Douglas Adams" });
return await interaction.editReply({ embeds: [help_embed, admin_embed] });
}
return await interaction.editReply({ embeds: [help_embed] });
} else if (command === "price") {
await interaction.deferReply();
let price_info;
try {
price_info = await songbird.get_price();
} catch (e) {
return await interaction.editReply("Failed to fetch coingecko API, probably you are requesting too fast (ratelimits)!");
}
let price_embed = new discord.EmbedBuilder();
price_embed.setTitle("Astral Credits Price");
price_embed.setURL("https://www.coingecko.com/en/coins/astral-credits");
price_embed.setColor("#ea8b17");
price_embed.addFields([
{
name: "Price in USD",
value: "$"+price_info.base_token_price_usd.slice(0, 13)
},
{
name: "Price in SGB",
//value: price_info.quote_token_price_usd
value: String(Number(price_info.base_token_price_usd)/Number(sgb_price_cache)).slice(0, 7)
},
{
name: "Estimated Market Cap",
value: "$"+String(util.format_commas(Math.round(Number(price_info.base_token_price_usd)*1000000000)))
},
]);
price_embed.setFooter({ text: "Made by prussia.dev" });
//create graph and add
//if (historic_data_cache) {
//let data_buffer = await chart.create_price_graph(historic_data_cache.ohlcv_list);
//let file = new discord.AttachmentBuilder(data_buffer);
//file.setName("chart.png");
//price_embed.setImage("attachment://chart.png");
//return await interaction.editReply({ embeds: [price_embed], files: [file] });
//} else {
//return await interaction.editReply({ embeds: [price_embed] });
//}
return await interaction.editReply({ embeds: [price_embed] });
} else if (command === "pools") {
if (!historic_data_cache) {
return interaction.reply("Failed, pool data currently unavaliable.");
}
let pools_embed = new discord.EmbedBuilder();
pools_embed.setTitle("Pools");
pools_embed.setColor("#3cb707");
pools_embed.addFields([
{
name: "FeatherSwap",
value: "[Pool](https://featherswap.xyz/swap/?outputCurrency=0x61b64c643fccd6ff34fc58c8ddff4579a89e2723) | [GeckoTerminal](https://www.geckoterminal.com/songbird/pools/0x9cbc1cc3b29d8a61b1843df50b6e90261a692705)"
},
{
name: "BlazeSwap",
value: "[Pool](https://app.blazeswap.xyz/swap/?outputCurrency=0x61b64c643fccd6ff34fc58c8ddff4579a89e2723) | [GeckoTerminal](https://www.geckoterminal.com/songbird/pools/0xa49259d33f8bea503e59f3e75af9d43a119598c0)"
},
/*{
name: "BlazeSwap Volume (last 7 days)",
value: "$"+util.format_commas(String(Math.floor(historic_data_cache.ohlcv_list.slice(-7).map((item) => item[5]).reduce((total, num) => total+num))))+"~"
},*/
/*{
name: "BlazeSwap Liquidity",
value: "$"+util.format_commas(String(liqudity_cache))+"~"
},*/
{
name: "Pangolin",
value: "[Pool](https://app.pangolin.exchange/#/swap?outputCurrency=0x61b64c643fccd6ff34fc58c8ddff4579a89e2723) | [GeckoTerminal](https://www.geckoterminal.com/songbird/pools/0xdd06d19b1217423ba474783a16e4a9798b794225)"
},
{
name: "OracleSwap",
value: "[Pool](https://dex.oracleswap.io/en/swap?outputCurrency=0x61b64c643fccd6ff34fc58c8ddff4579a89e2723) | [GeckoTerminal](https://www.geckoterminal.com/songbird/pools/0xc60d3d14a13739dba0fb6013a3530b975e21b1e5)"
}
]);
pools_embed.setFooter({ text: "Made by prussia.dev" });
return await interaction.reply({ embeds: [pools_embed] });
} else if (command === "next_claim") {
await interaction.deferReply({ ephemeral: true });
let address = await params.get("address");
let address_valid;
let user_info = await db.get_user(user.id);
if (!user_info && !address) return interaction.editReply("Failed, you are not registered, and have not provided any address.");
if (address) {
address = address.value.toLowerCase().trim();
} else {
address = user_info.address;
}
try {
address_valid = songbird.is_valid(address);
} catch (e) {
address_valid = false;
}
if (!address_valid) {
return await interaction.editReply(`Invalid address \`${address}\` provided`);
}
let next_claim_info = await db.get_next_claim_time(address);
let claim_embed = new discord.EmbedBuilder();
if (next_claim_info.enough_time && next_claim_info.under_claim_limit) {
claim_embed.setTitle("Claim Ready!");
claim_embed.setColor("#18ba7c");
claim_embed.setDescription(`The claim for \`${address}\` is ready! Remember - you will not be able to claim the faucet if you do not meet the holding (NFT or SGB) requirements.`);
} else {
claim_embed.setColor("#d1170a");
claim_embed.setTitle("Claim Not Ready!");
let fail_descrip = `The claim for \`${address}\` is not yet ready!`;
if (!next_claim_info.enough_time) {
fail_descrip += " Not enough time has lapsed since your last claim.";
}
if (!next_claim_info.under_claim_limit) {
fail_descrip += " The faucet is now CLOSED as we have reached the max no. of claims for the month! (11,111 claims). Please return when the faucet resets in the new month to claim again!";
}
claim_embed.setDescription(fail_descrip);
claim_embed.addFields([
{
name: "Next Claim",
value: "<t:"+String(next_claim_info.next_claim_time)+":R>"
}
]);
}
claim_embed.setFooter({ text: "Made by prussia.dev" });
return interaction.editReply({ embeds: [claim_embed] });
} else if (command === "faucet_stats") {
await interaction.deferReply({ ephemeral: true });
let faucet_stats = await db.get_faucet_stats();
let stats_embed = new discord.EmbedBuilder();
stats_embed.setTitle("Faucet Stats");
stats_embed.setColor("#d10dd8");
const remaining_claims = 11111-await db.get_claims_this_month();
if (remaining_claims <= 0) {
stats_embed.setDescription(`There are no more claims remaining this month! Faucet reset <t:${Math.floor(db.get_next_month_timestamp() / 1000)}:R>, halving <t:${Math.floor(db.get_next_halving_timestamp() / 1000)}:R>`);
} else {
stats_embed.setDescription(`There are ${remaining_claims} claims remaining this month!`);
}
stats_embed.addFields([
{
name: "Month #",
value: String(faucet_stats.month+1),
inline: true
},
{
name: "Current Payout",
value: String(faucet_stats.amount)+" XAC",
inline: true
},
{
name: "Claims This Month",
value: String(faucet_stats.claims_this_month),
inline: true
},
{
name: "Total Claims",
value: String(faucet_stats.total_claims),
inline: true
},
{
name: "Claims Last 24h",
value: String(faucet_stats.claims_last_day),
inline: true
},
{
name: "Total Unique Claimers",
value: String(faucet_stats.unique_claimers),
inline: true
},
{
name: "Total Burned",
value: String(burned_cache) + " XAC",
inline: true
}
]);
let user_info = await db.get_user(user.id);
if (user_info) {
stats_embed.addFields([
{
name: "Current Claim Streak",
value: String(user_info.achievement_data.faucet.current_streak),
inline: true
},
{
name: "Longest Claim Streak",
value: String(user_info.achievement_data.faucet.longest_streak),
inline: true
}
]);
}
stats_embed.setFooter({ text: "Made by prussia.dev" });
return interaction.editReply({ embeds: [stats_embed] });
} else if (command === "register") {
await interaction.deferReply();
let address = (await params.get("address")).value.toLowerCase().trim();
let address_valid;
try {
address_valid = songbird.is_valid(address);
} catch (e) {
address_valid = false;
}
if (!address_valid) {
return await interaction.editReply(`Invalid address \`${address}\` provided`);
}
let register = await db.register_user(user.id, address, false);
if (!register) {
return await interaction.editReply("You have already registered an address! Contact an admin if it needs to be changed. Or this address has already been registered.");
}
let register_embed = new discord.EmbedBuilder();
register_embed.setTitle("Successfully Registered!");
register_embed.setColor("#7ed11f");
register_embed.setDescription("Thanks for registering! You can now receive $XAC tips, prizes and giveaways.\n**PLEASE NOTE**: As a security measure, a team member must verify you before you can begin using the faucet. Thank you for your patience.");
register_embed.setFooter({ text: "Made by prussia.dev" });
return await interaction.editReply({ embeds: [register_embed] });
} else if (command === "faucet") {
await interaction.deferReply();
/*if (interaction.channel?.id !== "1098797717775462501") {
return await interaction.editReply("Failed, cannot use this command outside of the faucet claims channel.");
}*/
if (interaction.member.joinedTimestamp+(60*60*1000) > Date.now()) {
return await interaction.editReply("You joined the server in the last hour, try again after you've been in the server for 1 hour. Check out the announcements or talk or something.");
}
//make sure they are registered
let user_info = await db.get_user(user.id);
if (!user_info) {
return await interaction.editReply("Failed, please `/register` your address with the bot before using faucet.");
}
//make sure not too many claims this month
let claims_month = await db.get_claims_this_month();
if (claims_month >= MAX_CLAIMS_PER_MONTH) {
let next_claim_info = await db.get_next_claim_time(user_info.address); //after claims for the month exhausted, this will return the time of the new month
return await interaction.editReply(`<@${user.id}> We already reached this month's max claim limit (${claims_month} claims globally)! Please return when the faucet resets in the new month to claim again: <t:${next_claim_info.next_claim_time}:R>`);
}
//send captcha and modal thing with id set to code and nonce
let captcha_info;
try {
captcha_info = await util.get_text_captcha();
} catch (e) {
return await interaction.editReply("Captcha service appears to be down. Contact an admin if this not resolve within 15 minutes, or if your streak is lost as a result of this. If that is the case, an admin will restore your streak. Thank you for your patience.");
}
if (!captcha_info) {
return await interaction.editReply("Error, captcha probably currently down. Wait a bit and/or notify admins.");
}
//embed
let captcha_embed = new discord.EmbedBuilder();
captcha_embed.setTitle("One more step...");
captcha_embed.setColor("#2c16f7");
captcha_embed.setDescription("Please answer the captcha before you claim your XAC!");
const attachment = new discord.AttachmentBuilder(captcha_info.challenge_url, { name: "captcha.png" });
captcha_embed.setImage(`attachment://captcha.png`);
captcha_embed.setFooter({ text: "Almost there!" });
//send button that opens modal
let captcha_button = new discord.ButtonBuilder()
.setCustomId("capbtn-"+captcha_info.challenge_code+"-"+captcha_info.challenge_nonce+"-"+user.id+"-"+String(Date.now()))
.setLabel("Solve Captcha")
.setStyle("Primary");
let action_row = new discord.ActionRowBuilder();
action_row.addComponents(captcha_button);
return await interaction.editReply({ embeds: [captcha_embed], components: [action_row], files: [attachment] });
} else if (command === "add_website") {
await interaction.deferReply();
await interaction.member.fetch();
//does not have citizen role
if (!interaction.member.roles.cache.has("1071917333372739584")) {
return await interaction.editReply("Error, you must be citizen to set a linked URL.");
}
let website_url = (await params.get("website_url")).value.trim();
if (!website_url.startsWith("https://")) {
return await interaction.editReply("Error, url must start with `https://`");
} else if (website_url.includes("<") || website_url.includes(">")) {
return await interaction.editReply("Error, url cannot contain `<` or `>`");
}
//make sure user exists
let user_info = await db.get_user(user.id);
if (!user_info) {
return await interaction.editReply("Failed, please `/register` your address with the bot first.");
}
//add to db
await db.add_linked_website(user_info.address, website_url);
//embed
let website_embed = new discord.EmbedBuilder();
website_embed.setColor("#2dc4b5");
website_embed.setTitle("Website Linked!");
website_embed.setDescription("Website linked to your address. Now the website will show up on any pixels you place in the [Pixel Planet dApp](https://astralcredits.xyz/pixels).\nA reminder that linked websites are not allowed to contain illicit, offensive, NSFW, or virus content.");
return interaction.editReply({embeds: [website_embed]});
} else if (command === "pixels") {
return interaction.reply({ content: "https://astralcredits.xyz/pixels", ephemeral: true });
} else if (command === "domain") {
await interaction.deferReply({ ephemeral: true });
let domain = (await params.get("domain")).value.toLowerCase().trim();
if (Date.now() > DOMAIN_END*1000) {
return await interaction.editReply("The offer for the free Songbird Domain has ended, keep your eyes peeled for more exciting opportunities!");
}
if (!interaction.member.roles.cache.has("1071917333372739584")) {
return await interaction.editReply("Error, you must be citizen to participate");
}
if (domain.endsWith(".sgb")) {
return await interaction.editReply("Do not include the `.sgb`, it will be automatically added.");
}
if (domain.length < 5) {
return await interaction.editReply("Domain needs to be more than 5 characters long");
} else if (!util.valid_domain_name(domain)) {
return await interaction.editReply("Domain has illegal characters");
}
let user_info = await db.get_user(user.id);
if (!user_info) {
return await interaction.editReply("Please do `/register` first!");
}
let already_registered_bot = await db.check_domain_by_domain(domain);
let already_registered = await songbird.check_domain_owned(domain);
if (already_registered_bot || already_registered) {
return await interaction.editReply("That domain already exists - please try `/domain` again, selecting a different domain name.");
}
let already_domained = await db.check_domain_by_user(user.id);
if (already_domained) {
return await interaction.editReply("Sorry, you can't change your choice of domain, or get a second free domain.");
}
await db.add_domain(user.id, domain, user_info.address, already_domained);
let domain_embed = new discord.EmbedBuilder();
domain_embed.setTitle("Domain registered!");
domain_embed.setColor("#2d38d8");
domain_embed.setImage("https://cdn.discordapp.com/attachments/975616285075439636/1143434220417589310/ZQKKt6mI_400x400.jpg");
domain_embed.setFooter({ text: "Thanks to our partners at Songbird Domains!" });
domain_embed.setDescription("Your FREE domain has been submitted! Keep a look out for your .sgb NFT after this round of giveaways has been completed! The round will end <t:"+String(DOMAIN_END)+":R>\n- You can mint additional domains at [Songbird.Domains](https://songbird.domains/)\n- You can used your domain to join [sgb.chat](https://sgb.chat/)\n- Songbird's first Web3 social media platform!");
await interaction.editReply({ embeds: [domain_embed] });
let announce_embed = new discord.EmbedBuilder();
announce_embed.setColor("#2d38d8");
announce_embed.setThumbnail("https://cdn.discordapp.com/attachments/975616285075439636/1143434220417589310/ZQKKt6mI_400x400.jpg");
announce_embed.setDescription(`<@${user.id}> just registered their free Songbird Domain! Citizens can get one free (over 5 characters) by running \`/domain\`.\n\nMake sure to check out [Songbird Domains](https://songbird.domains) and [SGB Chat](https://sgb.chat/)!`);
announce_embed.setFooter({ text: "Thanks to our partners at Songbird Domains!" });
return interaction.channel.send({ embeds: [ announce_embed ] });
} else if (command === "coinflip_pvp") {
//unregistered
await interaction.deferReply();
let wager = (await params.get("wager")).value;
wager = Math.floor(wager);
if (wager < 1) {
return await interaction.editReply("Failed, cannot wager less than 1, 0, or negative XAC.");
} else if (wager > 10000) {
return await interaction.editReply("For now, wagers cannot be over ten thousand XAC.");
}
let pick = (await params.get("pick")).value.toLowerCase().trim();
if (pick !== "heads" && pick !== "tails") {
return await interaction.editReply("Must choose 'Heads' or 'Tails'.");
}
//check tipbot sgb and xac balance
let player1_address = songbird.get_tipbot_address(user.id);
let player1_sgb_bal = await songbird.get_bal(player1_address);
if (player1_sgb_bal < MIN_SGB) {
return await interaction.editReply(`Please deposit more SGB **into your tipbot wallet** to cover any gas fees (${MIN_SGB} SGB minimum).`);
}
let player1_astral_bal = await songbird.get_bal_astral(player1_address);
if (player1_astral_bal < wager) {
return await interaction.editReply("You do not have enough XAC **in your tipbot wallet** to cover the wager.");
}
const server_nonce = util.gen_server_nonce();
const hashed_server_nonce = util.hash(server_nonce);
await db.add_coinflip_pvp(interaction.id, user.id, wager, server_nonce, pick);
//send embed where people can enter their random thing
let coinflip_start_embed = new discord.EmbedBuilder();
coinflip_start_embed.setTitle("Play Coinflip!");
coinflip_start_embed.setColor("#2ae519");
coinflip_start_embed.setDescription(`<@${user.id}> has selected **${pick.toUpperCase()}**${ pick === "heads" ? " <:Heads:1157086933495840868>" : " <:Tails:1157086940777164942>" }\n\nTo cover the bet and join the game as **${pick === "heads" ? "TAILS" : "HEADS"}** click the button below! (Note: Both players must click the button below to start the game)`);
coinflip_start_embed.addFields([
{
name: "Wager Amount",
value: `${wager} XAC`,
},
{
name: "Server Nonce Hash",
value: "`"+hashed_server_nonce+"`",
}
]);
//coinflip_start_embed.setImage("https://cdn.discordapp.com/attachments/1087903395962179646/1155719287844126771/Spin.gif");
coinflip_start_embed.setFooter({ text: "Provably fair! Run `/provably_fair_pvp`." });
//send button that opens modal to enter in random string
let bet_button = new discord.ButtonBuilder()
.setCustomId("cfpvpbtn-"+interaction.id)
.setLabel("Bet!")
.setStyle("Primary");
let action_row = new discord.ActionRowBuilder();
action_row.addComponents(bet_button);
return await interaction.editReply({ embeds: [coinflip_start_embed], components: [action_row] });
} else if (command === "coinflip_pvh") {
//unregistered
await interaction.deferReply();
let wager = (await params.get("wager")).value;
wager = Math.floor(wager);
if (wager < 500) {
return await interaction.editReply("Failed, cannot wager less than 500 XAC.");
} else if (wager > 5000) {
return await interaction.editReply("Wagers cannot be over 5000 XAC.");
}
let pick = (await params.get("pick")).value.toLowerCase().trim();
if (pick !== "heads" && pick !== "tails") {
return await interaction.editReply("Must choose 'Heads' or 'Tails'.");
}
//check player balance
let player_address = songbird.get_tipbot_address(user.id);
let player_sgb_bal = await songbird.get_bal(player_address);
if (player_sgb_bal < MIN_SGB) {
return await interaction.editReply(`Please deposit more SGB **into your tipbot wallet** to cover any gas fees (${MIN_SGB} SGB minimum).`);
}
let player_astral_bal = await songbird.get_bal_astral(player_address);
if (player_astral_bal < wager) {
return await interaction.editReply("You do not have enough XAC **in your tipbot wallet** to cover the wager.");
}
//check house balance (bet amount + 10k for safety)
let house_address = songbird.get_tipbot_address(0);
if (await songbird.get_bal(house_address) < MIN_SGB) {
return await interaction.editReply("House does not have enough SGB to pay for fees.");
} else if (await songbird.get_bal_astral(house_address) < 5000 + wager) {
return await interaction.editReply("House does not have enough XAC to play (house needs wager + 5k).");
}
//gen server nonce
const server_nonce = util.gen_server_nonce();
const hashed_server_nonce = util.hash(server_nonce);
//add to db
await db.add_coinflip_pvh(interaction.id, user.id, wager, server_nonce, pick);
//send embed with button that opens up modal
let coinflip_start_embed = new discord.EmbedBuilder();
coinflip_start_embed.setTitle("Coinflip against the House!");
coinflip_start_embed.setColor("#2ae519");
coinflip_start_embed.setDescription(`You (<@${user.id}>) have selected **${pick.toUpperCase()}**${ pick === "heads" ? " <:Heads2:1167286494046720041>" : " <:Tails2:1167286498593345557>" }\n\nNow you just need to click the button below to complete the bet.`);
coinflip_start_embed.addFields([
{
name: "Wager Amount",
value: `${wager} XAC`,
},
{
name: "Server Nonce Hash",
value: "`"+hashed_server_nonce+"`",
}
]);
//coinflip_start_embed.setImage("https://cdn.discordapp.com/attachments/1087903395962179646/1155719287844126771/Spin.gif");
coinflip_start_embed.setFooter({ text: "Provably fair! Run `/provably_fair_pvh`." });
//send button that opens modal to enter in random string
let bet_button = new discord.ButtonBuilder()
.setCustomId("cfpvhbtn-"+interaction.id)
.setLabel("Bet!")
.setStyle("Primary");
let action_row = new discord.ActionRowBuilder();
action_row.addComponents(bet_button);
return await interaction.editReply({ embeds: [coinflip_start_embed], components: [action_row] });
} else if (command === "provably_fair_pvp") {
//explain why the pvp game is provably fair. but for now...
return await interaction.reply("https://github.com/Astral-Credits/Astral-Credits-Bot/blob/master/verifiers/coinflip_pvp.js");
} else if (command === "provably_fair_pvh") {
//explain why the pvh game is provably fair. but for now...
return await interaction.reply("https://github.com/Astral-Credits/Astral-Credits-Bot/blob/master/verifiers/coinflip_pvh.js");
} else if (command === "crawl") {
//while not an admin id guarded command, mkzi still has this command hidden for most non-admin people and channels
await interaction.deferReply({ ephemeral: true });
try {
let address = (await params.get("address")).value.toLowerCase().trim();
let known_only = (await params.get("known_only")).value;
let address_valid;
try {
address_valid = songbird.is_valid(address);
} catch (e) {
address_valid = false;
}
if (!address_valid) {
return await interaction.editReply(`Invalid address \`${address}\` provided`);
}
let associates = await songbird.find_associated(address);
//sort associates
//probably, not everything needs to be sorted
let sorted_associates = Object.entries(associates).sort((a, b) => b[1] - a[1]);
const initial_content = `**Crawl Results${ known_only ? "" : " (Top 25)" }:**\n`;
let content = initial_content;
let current_count = 0;
let ignore_list = ["0x61b64c643fccd6ff34fc58c8ddff4579a89e2723"]; //what is this, again? some exchange address mistakenly registered?
for (let i=0; i < sorted_associates.length; i++) {
//if known_only is true, more than 25 can be displayed
if (current_count === 25 && !known_only) break;
let found_address = sorted_associates[i][0];
let found_user = await db.get_user_by_address(found_address);
if (found_user && !ignore_list.includes(found_address)) {
content += `<@${found_user.user}> (${found_address}): ${sorted_associates[i][1]} transactions\n`;
} else if (known_only) {
//skip
continue;
} else if (Object.keys(songbird.SPECIAL_KNOWN).includes(found_address.toLowerCase())) {
content += `${songbird.SPECIAL_KNOWN[found_address]} (${found_address}): ${sorted_associates[i][1]} transactions\n`;
} else {
content += `${found_address}: ${sorted_associates[i][1]} transactions\n`;
}
current_count++;
}
if (content.length > 2000) {
const attachment = new discord.AttachmentBuilder(Buffer.from(content), { name: `${address}.txt` });
return interaction.editReply({ content: "Too big to send as embed, sending as text file", files: [attachment]});
}
if (content === initial_content) {
content += "No results.";
}
return await interaction.editReply(content);
} catch (e) {
console.log(e);
return await interaction.editReply("Encountered error");
}
} else if (command === "unlocked_achievements") {
const dresp = await interaction.deferReply();
//show unlocked achievements for user
let user_info = await db.get_user(user.id);
if (!user_info) {
return await interaction.editReply("Please do `/register` first!");
}
const all_achievements = Object.keys(db.ACHIEVEMENTS).length;
let unlocked_infos = user_info.achievements.map((a) => db.ACHIEVEMENTS[a]);
let unlocked_num = unlocked_infos.length;
//todo: pagination and stuff (if more than 25 achievements)
if (unlocked_num > 10) {
//pagination and stuff
const max_pages = Math.ceil(unlocked_num / 10);
let unlocked_embeds = [];
for (let i=0; i < max_pages; i++) {
let unlocked_embed = new discord.EmbedBuilder();
if (unlocked_num < all_achievements / 3) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1210017913038184468/Badge1.png?ex=65e907ff&is=65d692ff&hm=7f19adfc0753cb7e5888da82d19c5f055263cef5b4f593d6cbd5028b8cfc9927&");
} else if (unlocked_num < all_achievements / 3 * 2) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1210018490371678228/Badge2.png?ex=65e90889&is=65d69389&hm=b5626c6a881ce6bb92cfcf92e2e40ac6b3f6b7b8c4d165d553743b3a3e48ff08&");
} else if (unlocked_num < all_achievements) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1210019041197162496/Badge3.png?ex=65e9090c&is=65d6940c&hm=37e0460d8364b3dd18d7ff1f076e5573e2c943e10bfaa6d0e49a5571af2ca0ce&");
} else if (unlocked_num === all_achievements) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1209275707180720168/Badge_FINAL.gif?ex=65e654c3&is=65d3dfc3&hm=ee2f28842f4b158744b658709c37804f7ab1ea999d7c1b3a9393337f1fd15c1b&");
}
unlocked_embed.setTitle("Unlocked Achievements");
unlocked_embed.setDescription("Do `/locked_achievements` to see achievements yet to be unlocked.");
unlocked_embed.addFields(unlocked_infos.slice(10*i, 10*i+10).map((u) => ({ name: u.name, value: `${u.description} ${u.prize} XAC` })));
unlocked_embed.setColor("#689F38");
unlocked_embed.setFooter({ text: `${unlocked_num}/${Object.keys(db.ACHIEVEMENTS).length} unlocked` });
unlocked_embeds.push(unlocked_embed);
}
let action_row = new discord.ActionRowBuilder();
let action_back = new discord.ButtonBuilder()
.setCustomId("-1")
.setLabel("Back")
.setEmoji("⬅️")
.setDisabled(true)
.setStyle("Primary");
let action_front = new discord.ButtonBuilder()
.setCustomId("1")
.setLabel("Foward")
.setEmoji("➡️")
.setStyle("Primary");
action_row.addComponents(action_back, action_front);
//components
await interaction.editReply({
embeds: [unlocked_embeds[0]],
components: [action_row],
});
while (true) {
try {
//button interaction
let dresp_bin = await dresp.awaitMessageComponent({ filter: (bin) => bin.user.id === interaction.user.id, time: 60000 });
await dresp_bin.deferUpdate();
//update
let action_row = new discord.ActionRowBuilder();
let action_back = new discord.ButtonBuilder()
.setCustomId(String(Number(dresp_bin.customId)-1))
.setEmoji("⬅️")
.setDisabled(Number(dresp_bin.customId) === 0)
.setStyle("Primary");
let action_front = new discord.ButtonBuilder()
.setCustomId(String(Number(dresp_bin.customId)+1))
.setEmoji("➡️")
.setDisabled(Number(dresp_bin.customId) === max_pages - 1)
.setStyle("Primary");
action_row.addComponents(action_back, action_front);
//dresp_bin.customId will be the page to move to
await interaction.editReply({
embeds: [unlocked_embeds[Number(dresp_bin.customId)]],
components: [action_row],
});
} catch (e) {
return;
}
}
} else {
let unlocked_embed = new discord.EmbedBuilder();
unlocked_embed.setTitle("Unlocked Achievements");
if (unlocked_num < all_achievements / 3) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1210017913038184468/Badge1.png?ex=65e907ff&is=65d692ff&hm=7f19adfc0753cb7e5888da82d19c5f055263cef5b4f593d6cbd5028b8cfc9927&");
} else if (unlocked_num < all_achievements / 3 * 2) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1210018490371678228/Badge2.png?ex=65e90889&is=65d69389&hm=b5626c6a881ce6bb92cfcf92e2e40ac6b3f6b7b8c4d165d553743b3a3e48ff08&");
} else if (unlocked_num < all_achievements) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1210019041197162496/Badge3.png?ex=65e9090c&is=65d6940c&hm=37e0460d8364b3dd18d7ff1f076e5573e2c943e10bfaa6d0e49a5571af2ca0ce&");
} else if (unlocked_num === all_achievements) {
unlocked_embed.setThumbnail("https://cdn.discordapp.com/attachments/1070194353768775761/1209275707180720168/Badge_FINAL.gif?ex=65e654c3&is=65d3dfc3&hm=ee2f28842f4b158744b658709c37804f7ab1ea999d7c1b3a9393337f1fd15c1b&");
}
if (unlocked_num === 0) {
unlocked_embed.setDescription("You haven't unlocked any achievements yet. Do `/locked_achievements` to see achievements yet to be unlocked.");
} else {
unlocked_embed.setDescription("Do `/locked_achievements` to see achievements yet to be unlocked.");
unlocked_embed.addFields(unlocked_infos.map((u) => ({ name: u.name, value: `${u.description} ${u.prize} XAC` })));
}
unlocked_embed.setColor("#689F38");
unlocked_embed.setFooter({ text: `${unlocked_num}/${Object.keys(db.ACHIEVEMENTS).length} unlocked` });
return await interaction.editReply({ embeds: [unlocked_embed] });
}
} else if (command === "locked_achievements") {
const dresp = await interaction.deferReply({ ephemeral: true });
//show locked achievements for user
let user_info = await db.get_user(user.id);
if (!user_info) {
return await interaction.editReply("Please do `/register` first!");
}
let locked_infos = Object.values(db.ACHIEVEMENTS).filter((a) => !user_info.achievements.includes(a.id));
//todo: pagination and stuff (if more than 25 achievements)
if (locked_infos.length > 10) {
//pagination and stuff
const max_pages = Math.ceil(locked_infos.length / 10);
let locked_embeds = [];
for (let i=0; i < max_pages; i++) {
let locked_embed = new discord.EmbedBuilder();
locked_embed.setTitle("Locked Achievements");
locked_embed.setDescription("Do `/unlocked_achievements` to see your achievements.");
locked_embed.addFields(locked_infos.slice(10*i, 10*i+10).map((u) => ({ name: u.name, value: `${u.description} ${u.prize} XAC` })));
locked_embed.setColor("#B71C1C");
locked_embed.setFooter({ text: `${Object.keys(db.ACHIEVEMENTS).length - locked_infos.length}/${Object.keys(db.ACHIEVEMENTS).length} unlocked` });
locked_embeds.push(locked_embed);
}
let action_row = new discord.ActionRowBuilder();
let action_back = new discord.ButtonBuilder()
.setCustomId("-1")
.setLabel("Back")
.setEmoji("⬅️")
.setDisabled(true)
.setStyle("Primary");
let action_front = new discord.ButtonBuilder()
.setCustomId("1")
.setLabel("Foward")
.setEmoji("➡️")
.setStyle("Primary");
action_row.addComponents(action_back, action_front);
//components
await interaction.editReply({
embeds: [locked_embeds[0]],
components: [action_row],
});
while (true) {
try {
//button interaction
let dresp_bin = await dresp.awaitMessageComponent({ filter: (bin) => bin.user.id === interaction.user.id, time: 60000 });
await dresp_bin.deferUpdate();
//update
let action_row = new discord.ActionRowBuilder();
let action_back = new discord.ButtonBuilder()
.setCustomId(String(Number(dresp_bin.customId)-1))
.setEmoji("⬅️")
.setDisabled(Number(dresp_bin.customId) === 0)
.setStyle("Primary");
let action_front = new discord.ButtonBuilder()
.setCustomId(String(Number(dresp_bin.customId)+1))
.setEmoji("➡️")
.setDisabled(Number(dresp_bin.customId) === max_pages - 1)
.setStyle("Primary");
action_row.addComponents(action_back, action_front);
//dresp_bin.customId will be the page to move to
await interaction.editReply({
embeds: [locked_embeds[Number(dresp_bin.customId)]],
components: [action_row],
});
} catch (e) {
return;
}
}
} else {
let locked_embed = new discord.EmbedBuilder();
locked_embed.setTitle("Locked Achievements");
if (locked_infos.length === 0) {
locked_embed.setDescription("You've unlocked all achievements! Whew... :tada:");
} else {
locked_embed.setDescription("Do `/unlocked_achievements` to see your achievements.");
locked_embed.addFields(locked_infos.map((u) => ({ name: u.name, value: `${u.description} ${u.prize} XAC` })));
}
locked_embed.setColor("#B71C1C");
locked_embed.setFooter({ text: `${Object.keys(db.ACHIEVEMENTS).length - locked_infos.length}/${Object.keys(db.ACHIEVEMENTS).length} unlocked` });
return await interaction.editReply({ embeds: [locked_embed] });
}
} else if (command === "claim_achievements") {
await interaction.deferReply();
let user_info = await db.get_user(user.id);
if (!user_info) {
return await interaction.editReply("Please do `/register` first!");
}
//for non automatically rewarded achievements
let given = [];
//pixel planet
if (pptr_cache?.filter((t) => t.from === user_info.address).length > 0) {
let g = await add_achievement(user.id, "pixel-planet", user_info, interaction.member);
if (g) {
given.push(db.ACHIEVEMENTS["pixel-planet"].name);
await sleep(2500);
}
}
//discord boosts