-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
917 lines (896 loc) · 29.5 KB
/
index.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
process.title = "Broskie";
const fs = require("fs");
const path = require("path");
require("colors");
const {
Client,
GatewayIntentBits,
EmbedBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ModalBuilder,
TextInputBuilder,
TextInputStyle,
MessagePayload,
} = require("discord.js");
const wait = require("node:timers/promises").setTimeout;
const started = new Date();
const { Autocatcher } = require("./autocatcher");
const { prefix, owners } = require("./config");
const config = require("./config");
const { log, chunk, getGuilds, commatize, getRate } = require("./utils/utils");
const poketwo = "716390085896962058";
const p2Filter = (p2Msg) => p2Msg.author.id == poketwo;
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
});
let autocatchers = [],
tokens = [];
global.acs = autocatchers;
bot.on("ready", async () => {
log(`Connected as ${bot.user.tag}`.green);
});
bot.login(config.token);
let acs = autocatchers;
async function statRow(i, userId, defId) {
if (!defId)
await i.deferReply({
ephemeral: true,
});
else
await i
.update({
content: `Loading new guild...`,
embeds: [],
})
.catch(async (err) => {
await i.editReply({
content: `Refreshing...`,
embeds: [],
});
});
let id = userId || i.values[0].split("-")[1].trim();
let ac = autocatchers.find((x) => x.client.user.id == id);
//let ac = autocatchers.find((x) => x.client.user.id == id);
if (ac && ac.client.user) {
const embed = new EmbedBuilder();
embed
.setTitle(
`${
ac.client.user.globalName || ac.client.user.displayName || `User`
}'s stats`
)
.setColor(ac.client.user.hexAccentColor)
.setThumbnail(ac.client.user.displayAvatarURL({ format: `png` }));
let statStr = ``;
statStr += `• Balance: `.cyan + `${commatize(ac.stats.tcoins)}\n`.blue;
statStr += `• Coins: `.cyan + `${commatize(ac.stats.coins)}\n`.blue;
statStr += `• Total: `.cyan + `${ac.stats.catches}\n`.blue;
statStr += `• Legendaries: `.cyan + `${ac.stats.legs}\n`.green;
statStr += `• Mythicals: `.cyan + `${ac.stats.myths}\n`.green;
statStr += `• Ultreal Beasts: `.cyan + `${ac.stats.ubs}\n`.green;
statStr += `• IVs: `.cyan + `${ac.stats.ivs}\n`.magenta;
statStr += `• Events: `.cyan + `${ac.stats.events}\n`.magenta;
statStr += `• Forms: `.cyan + `${ac.stats.forms}\n`.magenta;
statStr += `• Shinies: `.cyan + `${ac.stats.shinies}\n`.yellow;
embed.setDescription(
`**ID:** \`${ac.client.user.id}\`\n` + "```ansi\n" + statStr + "```"
);
embed.setFields([
{
name: `__Broskie__`,
value: `**Uptime:** <t:${Math.floor(ac.init / 1000)}:R>\n**Captcha:** ${
ac.captcha ? `:grey_exclamation: YES` : `:x:`
}`,
},
]);
let guilds = await getGuilds(ac.client);
let defaultGuildId = defId || (guilds[1] ? guilds[1].id : null);
let defaultGuild = guilds[0].find((x) => x.id == defaultGuildId);
if (!defaultGuild) {
if (defId) {
await i.editReply({
content: `Unable to load this command!\n> \`Please check ${ac.client.user.tag}!\``,
embeds: [],
ephemeral: true,
components: [],
});
} else
await i.editReply({
content: `Unable to load this command!\n> \`Please check ${ac.client.user.tag}!\``,
embeds: [],
ephemeral: true,
components: [],
});
}
// Using Promise.all to await all promises in parallel
let opts = await Promise.all(
guilds[0].map(async (x) => {
let p2;
try {
p2 = await x.members.fetch("716390085896962058");
} catch (error) {}
let menu = new StringSelectMenuOptionBuilder()
.setLabel(`${x.name}`)
.setDescription(
`${x.hasP2 ? `✌ ` : ``}${x.hasAssistant ? `🤖 ` : ``}Channels: ${
x.channels.cache.size
} | Members: ${x.memberCount}`
)
.setValue(`setguild-${x.id}-${ac.client.user.id}`);
if (p2) menu.setEmoji("<:SM_dott:1232763727707902053>");
if (defaultGuildId === x.id) menu.setDefault(true);
return menu;
})
);
const guildRow = new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId("guilds-" + ac.client.user.id)
.setPlaceholder("Guilds")
.setOptions(...opts)
);
const btnRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(`x-say-${ac.client.user.id}`)
.setLabel(`Say`)
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId(`x-shards-${ac.client.user.id}`)
.setLabel(`Shards`)
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId(`x-mbuy-${ac.client.user.id}`)
.setLabel(`Market Buy`)
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId(`x-inc-${ac.client.user.id}`)
.setLabel(`Incense`)
.setStyle(ButtonStyle.Secondary)
);
const addRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(`add-p2-${ac.client.user.id}-${defaultGuild.id}`)
.setLabel(`Add Poketwo`)
.setEmoji(`<:poketwo:1233109744936419348>`)
.setStyle(ButtonStyle.Secondary)
.setDisabled(defaultGuild.hasP2),
new ButtonBuilder()
.setCustomId(`add-p2ass-${ac.client.user.id}-${defaultGuild.id}`)
.setLabel(`Add PokeAssistant`)
.setEmoji(`<:starly:1233109848258777118>`)
.setStyle(ButtonStyle.Secondary)
.setDisabled(defaultGuild.hasAssistant)
);
if (defId) {
await i.editReply({
content: ``,
embeds: [embed],
ephemeral: true,
components: [guildRow, btnRow, addRow],
});
} else
await i.editReply({
content: ``,
embeds: [embed],
ephemeral: true,
components: [guildRow, btnRow, addRow],
});
} else {
if (defId) {
await i.update({
content: `Unable to find that guy!`,
ephemeral: true,
});
} else
await i.editReply({
content: `Unable to find that guy!`,
ephemeral: true,
});
}
}
bot.on("interactionCreate", async (i) => {
if (i.isStringSelectMenu()) {
if (i.customId.startsWith("guilds")) {
const ids = i.values[0].split("-");
await statRow(i, ids[2], ids[1]);
}
if (i.customId.startsWith("pokemenu")) {
let opts = i.values;
let page = parseInt(i.customId.split("-")[1]);
let pokemons = autocatchers.map((x) => x.catches).flat();
pokemons = pokemons.sort((x, b) => b.iv - x.iv);
console.log(pokemons.length);
let strings = pokemons.map((x, i) => {
return {
rarity: x.rarity.toLowerCase(),
str: pokeToString(x, i + 1, x.rarity),
};
});
let options = [
"Shiny",
"Legendary",
"Rare IV",
"Mythical",
"Ultra Beast",
"Event",
"Regular",
];
strings = strings.filter((x) =>
opts.map((x) => x.toLowerCase()).includes(x.rarity)
);
let pages = chunk(strings, 20);
let embed = buildPokeMessage(
pages,
opts.map((x) => x.toLowerCase()),
page
);
let btnRow = getPokeBtn(i, page.length);
let menu = getPokeMenu(options, opts, page);
await i.update({
embeds: [embed],
components: [new ActionRowBuilder().addComponents(menu), btnRow],
});
}
}
if (i.customId.startsWith("statRow")) {
await statRow(i);
}
if (i.customId.startsWith(`statPage`)) {
statMsg(i, parseInt(i.customId.split("-")[2]));
}
if (i.isButton()) {
if (i.customId.startsWith(`pokemenu`)) {
let curPage = parseInt(i.customId.split('-')[1])
let pos = i.customId.split('-')[2]
let newPage = 0;
if(pos == `L`) newPage = curPage-1
else newPage = curPage+1
let pokemons = autocatchers.map((x) => x.catches).flat();
pokemons = pokemons.sort((x, b) => b.iv - x.iv);
let strings = pokemons.map((x, i) => {
return {
rarity: x.rarity.toLowerCase(),
str: pokeToString(x, i + 1, x.rarity),
};
});
let options = [
"Shiny",
"Legendary",
"Rare IV",
"Mythical",
"Ultra Beast",
"Event",
"Regular",
];
strings = strings.filter((x) =>
options.map((x) => x.toLowerCase()).includes(x.rarity.toLowerCase())
);
let pages = chunk(strings, 20);
let embed = buildPokeMessage(
pages,
options.map((x) => x.toLowerCase()),
newPage
);
let btnRow = getPokeBtn(newPage, pages.length);
let menu = getPokeMenu(options, [], newPage);
await i.update({
embeds: [embed],
components: [new ActionRowBuilder().addComponents(menu), btnRow],
});
}
}
if (i.customId.startsWith("x")) {
let args = i.customId.split("-");
let selected = i.message.components[0];
// Check if selected component exists
if (!selected) {
return await i.reply({
content: `ERROR: Component not found.`,
ephemeral: true,
});
}
let values = selected.components[0]?.data?.options;
if (!values) {
return await i.reply({
content: `ERROR: Options not found.`,
ephemeral: true,
});
}
let def = values.find((x) => x?.default);
if (!def) {
return await i.reply({
content: `ERROR: Guild not found.`,
ephemeral: true,
});
}
let guildId = def.value.split("-")[1];
const modal = new ModalBuilder()
.setCustomId(`run-${args[1]}-${args[2]}-${guildId}`)
.setTitle(`Broskie`);
if (args[1] == `say`) {
const input = new TextInputBuilder()
.setCustomId("content")
.setRequired(true)
.setPlaceholder(`Use 'p2' for mentioning Poketwo`)
.setLabel("What do you want the broskie to say?")
.setStyle(TextInputStyle.Paragraph);
modal.addComponents(new ActionRowBuilder().addComponents(input));
await i.showModal(modal);
} else if (args[1] == `shards`) {
const input = new TextInputBuilder()
.setCustomId("amount")
.setLabel("How many shards?")
.setPlaceholder(`Number`)
.setRequired(true)
.setStyle(TextInputStyle.Short);
modal.addComponents(new ActionRowBuilder().addComponents(input));
await i.showModal(modal);
} else if (args[1] == `mbuy`) {
const input = new TextInputBuilder()
.setCustomId("id")
.setLabel("Market ID")
.setPlaceholder(`This cannot be undone!`)
.setRequired(true)
.setStyle(TextInputStyle.Short);
modal.addComponents(new ActionRowBuilder().addComponents(input));
await i.showModal(modal);
} else if (args[1] == `inc`) {
const input = new TextInputBuilder()
.setCustomId("amount")
.setLabel("How many incenses?")
.setPlaceholder(`Will start in channel with 'incense' in name...`)
.setRequired(true)
.setStyle(TextInputStyle.Short);
modal.addComponents(new ActionRowBuilder().addComponents(input));
await i.showModal(modal);
} else
await i.reply({
content: `Okay lil bro you want to send a ${args[1]} to ${guildId}?`,
ephemeral: true,
});
}
if (i.customId.startsWith("add-")) {
let args = i.customId.split("-");
let ids = {
p2: poketwo,
p2ass: `854233015475109888`,
};
let id = ids[args[1]];
await i.reply({
content: `*Adding **${
id == poketwo ? `Poketwo` : `Poketwo Assistant`
}** to ${args[3]}...*`,
ephemeral: true,
});
//add-p2-${ac.client.user.id}-${defaultGuild.id}
let ac = autocatchers.find((x) => x.client.user.id == args[2]);
if (!ac) return await i.editReply(`Failed to locate broskie!`);
console.log(`Adding bot...`);
let res = await ac.addBot(args[3], id);
if (`location` in res) {
await i.editReply(`[✅ Added bot!](${res.location})`);
await statRow(i, ac.client.user.id, args[3]);
} else await i.editReply(`Unable to add bot!\n\`\`\`\n${res}\`\`\``);
}
});
bot.on("interactionCreate", async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (!owners.includes(interaction.user.id))
return await interaction.reply({
content: `You dont own me?`,
ephemeral: true,
});
//customId run-type-userId-guildId
let args = interaction.customId.split("-");
//vars
let ac = autocatchers.find((x) => x.client.user.id == args[2]);
if (!ac)
return await interaction.reply({
content: "That account seems to be offline!",
ephemeral: true,
});
let guild = ac.client.guilds.cache.get(args[3]);
if (!guild)
return await interaction.reply({
content: "Seems like that guild is not available!",
ephemeral: true,
});
let channel =
guild.channels.cache.find((x) => x.name.startsWith("general")) ||
guild.channels.cache.find((x) => x.name.startsWith("spam")) ||
guild.channels.cache.find((x) => x.type == "GUILD_TEXT") ||
guild.channels.cache.first();
if (!channel)
return await interaction.reply({
content: "Unable to find a channel to execute the command!",
ephemeral: true,
});
//Completed checking vars
let i = await interaction.reply({ content: "Executing...", ephemeral: true });
if (args[1] == `say`) {
let content = interaction.fields.getTextInputValue("content");
if (content && content.length > 0) {
channel.send(`${content.replace(/p2/g, `<@${poketwo}>`)}`);
await i.edit(
`Delivered your message to \`${channel.name}\` in \`${guild.name}\``
);
} else await i.edit(`An error occured...`);
} else if (args[1] == `shards`) {
let amount = parseInt(interaction.fields.getTextInputValue("amount"));
if (isNaN(amount))
return await i.edit({
content: `Please provide a valid amount of shards!`,
});
channel.send(`<@${poketwo}> buy shards ${amount}`);
const filter = (f) => f.author.id == poketwo;
try {
let msg = await (
await channel.awaitMessages({
max: 1,
time: 10000,
filter: filter,
errors: ["time"],
})
).first();
await msg.clickButton();
await i.edit(
`Purchased ${amount} shards in \`${channel.name}\`/\`${guild.name}\``
);
} catch (error) {
await i.edit(`Unable to purchase! Please check if anything's wrong!`);
}
} else if (args[1] == `mbuy`) {
let id = parseInt(interaction.fields.getTextInputValue("id"));
if (isNaN(id)) return i.edit(`Please provide a valid Market ID!`);
channel.send(`<@${poketwo}> m buy ${id}`);
const collectorFilter = (m) => m.author.id == poketwo;
const collector = channel.createMessageCollector({
filter: collectorFilter,
time: 15_000,
});
collector.on("collect", async (m) => {
if (m.content.includes("you want to buy")) {
await m.clickButton();
let x = m.content.split(" ").reverse()[1];
await i.edit(`Purchased \`${id}\` for ${x} coins!`);
collector.stop();
} else if (m.content.includes("have enough Pokécoins")) {
await i.edit(`Insufficient funds? Broskie's broke...`);
collector.stop();
} else if (m.content.includes("find that listing!")) {
await i.edit(`Broskie's trynna buy air?`);
collector.stop();
}
});
} else if (args[1] == `inc`) {
let id = parseInt(interaction.fields.getTextInputValue("amount"));
if (isNaN(id)) return i.edit(`You gotta givme a number?`);
if (guild.channels.cache.size < id)
return i.edit(
`Broskie, that server doesn't even have that many channels!`
);
let channels = Array.from(guild.channels.cache.values()).filter((x) =>
x.name.includes("incense")
);
if (channels.length < id) {
let left = id - channels.length;
let list = Array.from(guild.channels.cache.values()).filter(
(x) => !x.name.includes("incense") && x.type == "GUILD_TEXT"
);
for (let i = 0; i < left; i++) channels.push(list[i]);
}
for (let i = 0; i < channels.length; i++) {
await channels[i].send(`<@${poketwo}> buy incense`);
await wait(500);
}
await i.edit(
`✅ Purchased incense on \`${channels.length}\` channels!` +
"```\n" +
channels.map((x) => `${x.name}`).join("\n") +
"```"
);
}
});
bot.on("messageCreate", async (message) => {
if (message.author.bot || !message.content.startsWith(prefix)) return;
let [command, ...args] = message.content.slice(prefix.length).split(" ");
command = command.toLowerCase();
args = args.map((x) => x.toLowerCase());
if (command == `ping`) {
let x = new Date().getTime();
let m = await message.reply("Pinging...");
await m.edit(`Pinged with **${new Date().getTime() - x}ms!**`);
}
if (command == `reload`) {
stop();
let logs = await start();
message.channel.send(
`✅ Reloaded!\n` + "```ansi\n" + logs.join("\n") + "```"
);
} else if (command == "add-token") {
let x = await message.reply(`*Attempting to add token...*`);
addToken(message.content.split(" ")[1], (res) => {
x.edit(
`${
res.startsWith("-") ? `❌ Unable to add token!` : `✅ Added token!`
}\n` +
"```ansi\n" +
res +
"```"
);
});
} else if (command == "stats") {
await statMsg(message, 0);
} else if (command == "help") {
let cmds = [
[`ping`, `Fetches server latency`],
[`reload`, `Reloads/Reconnects all broskies`],
[`add-token`, `Adds a new broskie`],
[`stats`, `Displays in-depth broskie informations`],
[`captcha`, `Toggle captcha on/off <id/global>`],
[`catcher`, `Toggle catcher on/off <id/global>`],
[`help`, `Shows this?`],
];
let str = cmds
.map((x) => {
return `• ${x[0].padEnd(10, ` `)} [-] ${x[1]}`;
})
.join("\n");
const embed = new EmbedBuilder()
.setTitle(`Broskie`)
.setColor(`Aqua`)
.setDescription(`lil bro, I'm on v1...\`\`\`\n${str}\`\`\``);
message.channel.send({
embeds: [embed],
});
} else if (command == `captcha`) {
let id = args[0];
if (!id)
return message.reply(
`Please give me an ID or mention if its global!\n\`${prefix}captcha <id/on/off>\``
);
id = id.toLowerCase();
if (args[0] == `on` || args[0] == `off`) {
let start = args[0] == `on`;
for (let i = 0; i < autocatchers.length; i++)
autocatchers[i].captcha = start;
await message.reply(
`Successfully toggled **${
start ? `on` : `off`
}** in captcha status globally!`
);
return;
}
id = parseInt(id);
if (isNaN(id)) return message.reply(`Please give me a valid ID!`);
let ac = autocatchers.find((x) => x.client.user.id == id);
if (!ac) return message.reply(`Unable to locate that broskie!`);
if (args[1]) {
if (args[1].toLowerCase() == `on`) ac.captcha = false;
if (args[1].toLowerCase() == `off`) ac.captcha = true;
}
message.reply(
`Captcha has been **toggled __${ac.captcha ? `OFF` : `ON`}__** for ${
ac.client.user.globalName || ac.client.user.displayName || `User`
}\n- Captcha URL: 🔗 [Link](https://verify.poketwo.net/captcha/${
ac.client.user.id
})`
);
ac.captcha = ac.captcha ? false : true;
} else if (command == `catcher`) {
let id = args[0];
if (!id)
return message.reply(
`Please give me an ID or mention if its global!\n\`${prefix}catcher <id/start/stop>\``
);
id = id.toLowerCase();
if (args[0] == `start` || args[0] == `stop`) {
let start = args[0] == `start`;
for (let i = 0; i < autocatchers.length; i++)
autocatchers[i].catch = start;
await message.reply(
`Successfully **${start ? `started` : `stopped`}** globally!`
);
return;
}
id = parseInt(id);
if (isNaN(id)) return message.reply(`Please give me a valid ID!`);
let ac = autocatchers.find((x) => x.client.user.id == id);
if (!ac) return message.reply(`Unable to locate that broskie!`);
if (!args[1])
return message.reply(
`Please give provide an option! => \`<start/stop>\``
);
args[1] = args[1].toLowerCase();
if (args[1] == `start` || args[1] == `stop`) {
let start = args[1] == `start`;
ac.catch = start;
await message.reply(
`Successfully **${start ? `started` : `stopped`}** ${
ac.client.user.globalName || ac.client.user.displayName || `User`
}!`
);
}
} else if (command == `pokemons`) {
let pokemons = autocatchers.map((x) => x.catches).flat();
pokemons = pokemons.sort((x, b) => b.iv - x.iv);
let strings = pokemons.map((x, i) => {
return {
rarity: x.rarity.toLowerCase(),
str: pokeToString(x, i + 1, x.rarity),
};
});
let options = [
"Shiny",
"Legendary",
"Rare IV",
"Mythical",
"Ultra Beast",
"Event",
"Regular",
];
strings = strings.filter((x) =>
options.map((x) => x.toLowerCase()).includes(x.rarity.toLowerCase())
);
let pages = chunk(strings, 20);
let embed = buildPokeMessage(
pages,
options.map((x) => x.toLowerCase()),
0
);
let btnRow = getPokeBtn(0, pages.length);
let menu = getPokeMenu(options, [], 0);
await message.channel.send({
embeds: [embed],
components: [new ActionRowBuilder().addComponents(menu), btnRow],
});
}
});
function getPokeBtn(i, len) {
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(`pokemenu-${i}-L`)
.setLabel(`◀`)
.setDisabled(i == 0)
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId(`pokemenu-${i}-R`)
.setLabel(`▶`)
.setDisabled((len == (i+1) || len == 0) ? true : false)
.setStyle(ButtonStyle.Secondary)
);
return row;
}
function getPokeMenu(options, optis, i) {
let opts = options.map((x) => {
return new StringSelectMenuOptionBuilder()
.setLabel(x)
.setDescription(`${x} pokemons!`)
.setValue(x.toLowerCase())
.setDefault(optis.includes(x.toLowerCase()));
});
return new StringSelectMenuBuilder()
.setCustomId(`pokemenu-${i}`)
.setPlaceholder(`Filter`)
.addOptions(...opts)
.setMaxValues(6);
}
function buildPokeMessage(pages, options, i) {
console.log(pages, i);
const embed = new EmbedBuilder()
.setTitle(`Broskie Autocatcher`)
.setColor(`LuminousVividPink`)
.setFooter({ text: `Showing page ${i + 1}/${pages.length}` });
if (i >= pages.length || i < 0) embed.setDescription(`*No pokemons*`);
else embed.setDescription(pages[i].map((x) => x.str).join("\n"));
return embed;
return {
embeds: [embed],
components: [new ActionRowBuilder().addComponents(menu)],
};
}
function pokeToString(data, i) {
/* {
name: name.trim(),
level: level,
gender: gender,
iv: iv,
shiny: str.includes("✨") || str.includes(":sparkles:"),
user: string,
rarity: string
};*/
return `\`${i}\` ${data.shiny ? `✨ ` : ``}**${data.name}** \`${
data.rarity.toLowerCase().includes("IV")
? "I"
: data.rarity.charAt(0).toUpperCase()
}\` ${
data.gender == "female"
? "♀️"
: data.gender == "male"
? `♂️`
: `:grey_question:`
} • Lvl. ${data.level} • ${data.iv}%`;
}
async function genStatMenu() {
let menus = autocatchers
.filter((x) => x.client.ws.status == 0)
.sort(
(a, b) =>
b.stats.coins + b.stats.tcoins - (a.stats.coins + a.stats.tcoins)
)
.map((ac) => {
let menu = new StringSelectMenuOptionBuilder()
.setLabel(
`${ac.stats.coins == 0 ? `👴` : ``}` +
(ac.client.user.globalName || ac.client.user.displayName || `User`)
)
.setEmoji(
`${
ac.client.ws.status == 0 ? `<:SM_dott:1232763727707902053>` : `🔴`
}`
)
.setDescription(
`Catches: ${ac.stats.catches} | ${(
Math.abs(ac.stats.lastCatch - new Date()) /
(1000 * 60)
).toFixed(2)}m ago`
)
.setValue(`stats-` + ac.client.user.id);
return menu;
});
menus = chunk(menus, 25);
let rows = menus.map((mns, i) => {
const select = new StringSelectMenuBuilder()
.setCustomId("statRow-" + i)
.setPlaceholder("Broskies?")
.addOptions(...mns);
const row = new ActionRowBuilder().addComponents(select);
return row;
});
return rows;
}
async function stop() {
autocatchers.map((ac) => {
if (ac) ac.client.destroy();
});
autocatchers = [];
return autocatchers;
}
async function start() {
let tokenz = fs
.readFileSync(path.join(__dirname, "data", "tokens.txt"))
.toString()
.split("\n");
console.log(`Loading ${tokenz.length} tokens...`.cyan);
let logs = await Promise.all(
tokenz.map((token) => {
return new Promise((resolve, reject) => {
console.log(`Logging into ${token}`.gray);
let loggedIn = false;
const ac = new Autocatcher(token.trim());
ac.login();
ac.start((res) => {
loggedIn = true;
resolve(res);
autocatchers.push(ac);
tokens.push(token);
});
ac.catcher();
setTimeout(() => {
if (!loggedIn)
resolve(
`- Failed to login into ${
token.substring(0, token.indexOf(".")) || `_token_`
}`
);
}, 5000);
});
})
);
return logs;
}
async function addToken(token, callback) {
const ac = new Autocatcher(token);
if (tokens.includes(token))
return callback(`- Autocatcher already exists!`.red);
ac.login();
let loggedIn = false;
ac.start((res) => {
callback(res);
loggedIn = true;
ac.catcher();
autocatchers.push(ac);
});
setTimeout(() => {
if (!loggedIn)
callback(
`- Failed to login into ${
token.substring(0, token.indexOf(".")) || `_token_`
} | Invalid Token?`.red
);
}, 5000);
return;
}
(async () => {
let x = await start();
})();
process.on("unhandledRejection", (error) => {
console.error("Unhandled promise rejection:", error);
});
async function statMsg(message, page) {
const embed = new EmbedBuilder().setTitle(`Connected broskies...`);
let bal = 0,
catches = 0;
let str = autocatchers
.filter((x) => x.client.ws.status == 0)
.map((x, i) => {
return {
name: `**${(
x.client.user.globalName ||
x.client.user.displayName ||
`User`
).padEnd(15, ` `)}**`,
catches: x.stats.catches,
bal: x.stats.coins + x.stats.tcoins,
ping: `<t:${Math.floor(x.stats.lastCatch / 1000)}:R>${
x.captcha
? `\n• ❕ [Captcha]((https://verify.poketwo.net/captcha/${ac.client.user.id})`
: ``
}`,
};
})
.sort((a, b) => b.bal - a.bal)
.map((x, i) => {
bal += x.bal;
catches += x.catches;
return `- \`${i + 1}\` ${x.name} • **${commatize(
x.catches
)}** • \`${commatize(x.bal)}\` • ${x.ping}`;
});
let chunks = chunk(str, 20);
let s =
`> \`i\` **Name** • **Catches** • **Balance** • **Ping**\n${`-`.repeat(
55
)}\n> **Broskies:** ${commatize(
autocatchers.length
)}\n> **Catches:** \`${commatize(catches)}\`\n> **Balance:** \`${commatize(
bal
)}\`\n> **Catch Rate:** \`${getRate(
started,
catches
)}\` *P/s*\n${`-`.repeat(55)}\n` + chunks[page || 0].join("\n");
s = s.length == 0 ? `*None*` : s;
embed.setDescription(`${s}`);
embed.setColor("DarkButNotBlack");
let id = "author" in message ? message.author.id : message.user.id;
const row = new ActionRowBuilder().setComponents(
new ButtonBuilder()
.setCustomId(`statPage-L-${page + 1}-${id}`)
.setLabel(`◀`)
.setDisabled(page == 0)
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId(`statPage-R-${page + 1}-${id}`)
.setLabel(`▶`)
.setDisabled(chunks.length == page + 1 ? true : false)
.setStyle(ButtonStyle.Secondary)
);
if ("author" in message)
message.channel.send({
embeds: [embed],
components: [...(await genStatMenu()), row],
});
else
message.update({
embeds: [embed],
components: [...(await genStatMenu()), row],
});
}