-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.ts
608 lines (579 loc) · 21.5 KB
/
index.ts
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
import {
Client,
Guild,
Message,
MessageEmbed,
TextChannel,
WebhookClient,
} from "discord.js-selfbot-v13";
import fs from "fs"
import axios from 'axios';
import { crusers, Logger, pokeList, randomBin, randomItem, stats } from "./structs/utils.js";
import config from "./config.json"
import { setTimeout as wait } from "node:timers/promises";
import { solveHint } from "./structs/pokemon.js";
import leg from "./data/names/legendary.json"
import myth from "./data/names/mythical.json"
import ubs from "./data/names/ultra-beast.json"
import reg from "./data/names/regional.json"
import evs from "./data/names/event.json"
import evImages from "./data/images/events.json"
import fmImages from "./data/images/forms.json"
import alImages from "./data/images/images.json"
import path from "node:path";
import chalk from "chalk";
const poketwo = [`716390085896962058`];
const mention = `<@716390085896962058>`;
const langOpts = [`english`, `french`, `german`, `japanese`];
const languages = langOpts
.map((x) => {
const raw = fs.readFileSync(`./data/langs/${x}.json`, `utf-8`);
try {
return JSON.parse(raw);
} catch (_) {
return {};
}
})
.filter((x) => x);
const legendariesSet = new Set(leg.map((p: string) => p.toLowerCase()));
const mythicalsSet = new Set(myth.map((p: string) => p.toLowerCase()));
const ultraBeastsSet = new Set(ubs.map((p: string) => p.toLowerCase()));
const regionalsSet = new Set(reg.map((p: string) => p.toLowerCase()));
const eventsSet = new Set(evs.map((p: string) => p.toLowerCase()));
const raritytags: { set: Set<string>; rarity: rarity }[] = [
{ set: legendariesSet, rarity: `leg` },
{ set: mythicalsSet, rarity: "myth" },
{ set: ultraBeastsSet, rarity: "ub" },
{ set: regionalsSet, rarity: "reg" },
{ set: eventsSet, rarity: "ev" },
];
type rarity = `leg` | `myth` | `ub` | `ev` | `reg` | `norm`;
interface Pokemon {
name: string;
level: number;
gender: `female` | `male` | `none`;
iv: number;
shiny: boolean;
rarity: rarity[];
loggable: boolean;
}
let tokenCounter = 0;
export class Crused {
token: string;
client = new Client({});
msgs: { message: string; channel: TextChannel; before?: Date }[] = [];
sending: boolean = false;
captcha: boolean = false;
shardFlag: Date = new Date(`1-1-2000`);
stats = {
catches: 0,
legendary: 0,
mythical: 0,
ultraBeast: 0,
gigantamax: 0,
event: 0,
iv: 0,
shiny: 0,
balance: 0,
shards: 0,
incense: {
total: [``],
active: [``]
}
};
count: number = ++tokenCounter;
webhook: WebhookClient;
constructor(token: string, webhook: string, count?: number) {
this.token = token;
this.webhook = new WebhookClient({ url: webhook });
if (count) this.count = count;
}
login() {
Logger.info(`Logging in...`);
this.client.on("ready", () => {
Logger.success(`Logged in as ${this.client?.user?.tag}!`);
stats.connected++;
});
this.client.login(this.token.trim()).catch(() => `Unable to login`);
}
run() {
this.client.on("messageCreate", async (message) => {
if (message.channel.type != "GUILD_TEXT") return;
if (poketwo.includes(message.author.id)) {
//Whoa there. Please tell us you're human! https://verify.poketwo.net/captcha/1312953630134898750
//Logger.error(this.client.user && message.content.includes(`Whoa there.`) && message.content.includes(this.client?.user?.id), this.client.user?.id, message.content, message.content.includes(`Whoa there.`))
if (this.client.user && message.content.includes(`Whoa there.`) && message.content.includes(this.client?.user?.id)) {
this.captcha = true;
message.react(`🥶`);
const hook = new WebhookClient({ url: config.captchaHook });
const embed = new MessageEmbed()
.setTitle(`Encountered new Captcha!`)
.setColor(`#6a00c7`)
.setThumbnail(this.client.user.displayAvatarURL())
.setDescription(`- **<:PurpleUser:1278707340727554090> Account**: \`${this.client.user.tag}\` \`(${this.client.user.id})\`\n- **<:purple_link:1278707443278413876> Message**: [#${message.channel.name}](${message.url})`)
let logStr = `Captcha on ` + chalk.underline(`${this.client.user.tag}`)
if (config.captchaKey.length != 0) {
embed.description = `-# ### ❕ Captcha Solver is __not available__!\n` + embed.description
logStr = chalk.hex(`#e8ff17`)`❕` + ` | ` + logStr
} else {
logStr = chalk.hex(`#ff3352`)`❌` + ` | ` + logStr
}
Logger.warn(logStr)
hook.send({
embeds: [embed]
})
if (config.captchaKey.length == 0) return;
let init = new Date();
let solved = await this.solve(message);
if (solved) {
this.captcha = false;
Logger.success(`✅ Solved captcha! ${chalk.hex(`#801fff`)`${this.client.user.tag}`}/${chalk.greenBright(((new Date().getTime() - init.getTime()) / 1000).toFixed(2))}s!`)
}
else {
this.captcha = true;
Logger.error(`❌ Failed captcha solve for ${this.client.user.tag}!`)
message.react(`🙀`)
}
}
if (
message.content.includes(`You have completed the quest`) &&
!message.content.includes(`badge!`)
) {
//You have completed the quest **Catch 500 pokémon originally found in the Paldea region.** and received **50,000** Pokécoins!
let x = message.content.split(" ");
let recIndex = x.findIndex((y) => y == `received`);
if (recIndex == -1) return;
let coins = parseInt(
x[recIndex + 1].replace(/,/g, "").replace(/\*/g, "")
);
if (!isNaN(coins)) {
pokeList.pc += coins;
this.stats.balance += coins;
}
}
if (message.content.includes(`You received`)) {
let x = message.content.split(" ");
let recIndex = x.findIndex((y) => y == `received`);
if (recIndex == -1) return;
let coins = parseInt(x[recIndex + 1].replace(/,/g, ""));
if (!isNaN(coins)) {
pokeList.pc += coins;
this.stats.balance += coins;
}
}
if (message.embeds.length != 0 && message.embeds[0]?.title) {
if (message.embeds[0].title.includes(`has appeared`)) {
if (!config.autocatch || this.captcha) return;
if (message.guild && message.embeds[0].footer && message.embeds[0].footer?.text?.includes(`Spawns`)) {
let spawnStr = message.embeds[0].footer.text.split(`\n`).find(x => x.includes(`Spawns`))
const spawns = parseInt(spawnStr?.split(' ')[2].replace(`.`, ``) || ``)
//`spam` | `incense` | `beast` | `eco`
if (!this.stats.incense.active.includes(message.channelId)) this.stats.incense.active.push(message.channelId)
if (!this.stats.incense.total.includes(message.channelId)) this.stats.incense.total.push(message.channelId)
if (spawns == 0) {
this.stats.incense.active.splice(this.stats.incense.active.indexOf(message.channelId), 1);
if (config.mode == `beast`) {
//Check quests
}
if (config.mode == `incense` || config.mode == `beast`) {
if (new Date().getTime() - this.shardFlag.getTime() > 1000 * 60) {
let bal = (await this.getBal(message.channel))
let shards = config.incense.atOnce * 1;
if (bal?.shards) shards -= bal.shards;
shards = Math.max(0, shards)
if (shards != 0) {
let purchased = await this.buyShards(shards, message.channel);
if (!purchased) Logger.error(`Shards not bought for ${this.client.user?.tag}!`)
else {
pokeList.pc -= shards;
this.stats.balance += shards;
}
}
this.buyIncense(message.guild);
}
}
}
}
const spawned = new Date();
this.sendMessage(
`${mention} ${randomBin([`hint`, `h`])}`,
message.channel,
new Date(spawned.getTime() + 1 * 1000),
);
}
}
if (message.content.includes(`The pokémon is`)) {
if (this.captcha || !config.autocatch) return;
const pokemons = solveHint(message.content);
this.catchPokemon(pokemons, message.channel);
}
}
});
}
async buyIncense(guild: Guild) {
const sendableChannels = guild.channels.cache.filter(x => x.type == `GUILD_TEXT` && !x.isThreadOnly());
const incenseChannels = sendableChannels.filter(x => x.name.startsWith(`incense`)).filter(X => X)
const spawnChannels = sendableChannels.filter(x => x.name.startsWith(`spawn`)).filter(X => X)
const spamChannels = sendableChannels.filter(x => x.name.startsWith(`spam`)).filter(X => X)
const channels = [...new Set([...incenseChannels.values(), ...spawnChannels.values(), ...spamChannels.values(), ...sendableChannels.values()])];
for (let i = 0; i < config.incense.atOnce; i++) {
this.sendMessage(`<@${poketwo[0]}> incense buy 1h 20s --confirm`, channels[i] as TextChannel)
}
}
async buyShards(amount: number, channel: TextChannel) {
await channel.send(`<@${poketwo[0]}> buy shards ${amount}`);
//Are you sure you want to exchange **200** Pokécoins for **1** shards? Shards are non-transferable and non-refundable!
const p2filter = (f: Message) =>
f.embeds && f.content.includes(`exchange`) && f.content.includes(`Shards`) && poketwo.includes(f.author.id);
let msg = (
await channel.awaitMessages({
filter: p2filter,
time: 10_000,
max: 1,
})
).first();
if ((msg?.components?.length || 0) > 0) {
let purchased = false;
while (!purchased) {
try {
let c = await msg?.clickButton()
if (c) purchased = true;
} catch (error) {
await wait(5000);
}
}
Logger.warn(`Purchased ${amount} S$ | ${this.client.user?.tag}!`)
return true;
}
else return false;
}
async getBal(channel: TextChannel) {
await channel.send(`<@${poketwo[0]}> bal`);
const p2filter = (f: Message) =>
f.embeds && f.embeds.length > 0 && poketwo.includes(f.author.id);
let msg = (
await channel.awaitMessages({
filter: p2filter,
time: 2000,
max: 1,
})
).first();
if (msg && `embeds` in msg && msg.embeds.length > 0 && msg.embeds[0]?.title?.includes(`balance`) && msg.embeds[0]?.fields?.length > 0) {
let rawBal = msg.embeds[0]?.fields[0]?.value;
let rawShards = msg.embeds[0]?.fields[1]?.value;
const bal = parseInt(rawBal?.replace(/,/g, ""));
const shards = parseInt(rawShards?.replace(/,/g, ""));
if (!isNaN(bal) && !isNaN(shards)) {
this.stats.balance = bal
return {
bal,
shards
}
};
Logger.info(`Updated ${this.client.user?.tag}'s balance ${chalk.cyanBright(bal.toLocaleString())} PC!`)
}
else return;
}
catchPokemon(pokemons: string[], channel: TextChannel) {
const maxTries = 2;
let tries = 0;
const collector = channel.createMessageCollector({
//filter: filter,
time: 15_000,
});
collector.on(`collect`, async (msg) => {
if (msg.content.startsWith(`Congratulations`)) {
collector.stop();
if (msg.client.user && msg.content.includes(msg.client.user?.id)) {
const pokemon = this.parsePokemon(msg.content);
//console.log(pokemon);
this.stats.catches++;
if (pokemon?.rarity.includes(`ev`)) this.stats.event++;
if (pokemon?.rarity.includes(`leg`)) this.stats.legendary++;
if (pokemon?.rarity.includes(`ub`)) this.stats.ultraBeast++;
if (pokemon?.rarity.includes(`myth`)) this.stats.mythical++;
if (pokemon?.shiny) this.stats.shiny++;
if (pokemon?.loggable) {
this.logPokemon(pokemon, msg.url);
}
if (pokemon)
Logger.logPokemon(pokemon, msg as any)
if (this.stats.catches == 1 && this.stats.balance == 0) {
await channel.send(`<@${poketwo[0]}> bal`);
const p2filter = (f: Message) =>
f.embeds && f.embeds.length > 0 && poketwo.includes(f.author.id);
let msg = (
await channel.awaitMessages({
filter: p2filter,
time: 2000,
max: 1,
})
).first();
if (msg && `embeds` in msg && msg.embeds.length > 0 && msg.embeds[0]?.title?.includes(`balance`) && msg.embeds[0]?.fields?.length > 0) {
let rawBal = msg.embeds[0]?.fields[0]?.value;
const bal = parseInt(rawBal.replace(/,/g, ""));
if (!isNaN(bal)) {
this.stats.balance = bal
pokeList.pc += bal;
};
Logger.info(`Updated ${this.client.user?.tag}'s balance ${chalk.cyanBright(bal.toLocaleString())} PC!`)
}
}
}
} else if (
msg.embeds.length > 0 &&
msg.embeds[0]?.title?.includes(`wild pokémon`)
) {
collector.stop();
} else if (msg.content.includes(`That is the`)) {
if (tries == maxTries) return collector.stop();
if(!pokemons[tries]) return;
const names = this.getNames(pokemons[tries]);
names.push(pokemons[tries]);
this.sendMessage(
`${mention} ${randomBin([`c`, `catch`])} ${randomItem(names)}`,
channel,
);
tries++;
}
});
const names = this.getNames(pokemons[0]);
names.push(pokemons[0]);
this.sendMessage(
`${mention} ${randomBin([`c`, `catch`])} ${randomItem(names)}`,
channel,
);
tries++;
}
getNames(pokemon: string): string[] {
const names = languages
.map((language) => {
if (pokemon.toLowerCase() in language) {
return language[pokemon.toLowerCase()];
}
})
.filter((x) => x);
return names;
}
parsePokemon(content: string): Pokemon | null {
if (!content.startsWith("Congratulations")) return null;
const [_, main] = content.split("!").map((s) => s.trim());
const [_1, _2, _3, _4, levelStr, ...nameParts] = main.split(" ");
const level = parseInt(levelStr);
const name = nameParts.join(" ").split("<")[0].trim();
const iv = parseFloat(
nameParts.join(" ").match(/\((\d+(\.\d+)?)%\)/)?.[1] ?? "0",
);
const gender = name.includes("female")
? "female"
: name.includes("male")
? "male"
: "none";
let rarities: rarity[] = [];
let loggable = false;
for (const { set, rarity } of raritytags) {
if (set.has(name.toLowerCase())) {
rarities.push(rarity);
}
}
if (rarities.length === 0) rarities = ["norm"];
if (rarities[0] !== "norm") loggable = true;
return {
name,
level,
gender,
iv,
shiny: content.includes("✨") || content.includes(":sparkles:"),
rarity: rarities,
loggable,
};
}
getImage(pokemon: string) {
const name = pokemon.toLowerCase();
let tags = [
alImages[name as keyof typeof alImages],
evImages[name as keyof typeof evImages],
fmImages[name as keyof typeof fmImages],
];
tags = tags.filter((x) => x);
if (tags.length > 0) return tags[0];
else {
return `https://raw.githubusercontent.com/Z-Dux/Broskie-DB/main/ball.png`;
}
}
logPokemon(pokemon: Pokemon, url: string) {
const formats: Record<rarity, string> = {
leg: `🟥`,
myth: `🟨`,
ub: `🟩`,
ev: `⬜`,
reg: `🟪`,
norm: `🟦`,
};
const rNames: Record<rarity, string> = {
leg: `Legendary`,
myth: `Mythical`,
ub: `Ultra Beast`,
ev: `Event`,
reg: `Regional`,
norm: `Normal`,
};
const embed = new MessageEmbed()
.setTitle("Pokémon Caught")
.setDescription(
`- **Name** ※ \`${pokemon.name}\`
- **Level** ※ ${pokemon.level}
- **Shiny** ※ ${pokemon.shiny ? `Yes ✨` : `No`}
- **Gender** ※ ${pokemon.gender}
- **IV** ※ ${pokemon.iv}%
` +
"\n```\n" +
pokemon.rarity.map((x) => formats[x].repeat(8)).join("\n") +
"\n```",
)
.setURL(url)
.setColor(2961203)
.setAuthor({
name: "Crused v2.2.3",
url: "https://crused.sellauth.com/",
iconURL:
"https://raw.githubusercontent.com/Z-Dux/Broskie-DB/main/bew.png",
})
.setFooter({
text: pokemon.rarity.map((x) => rNames[x]).join(" | "),
})
.setThumbnail(this.getImage(pokemon.name));
this.webhook.send({ embeds: [embed] });
}
sendMessage(message: string, channel: TextChannel, before?: Date) {
this.msgs.push({
message,
channel,
before,
});
if (this.msgs.length == 1 && !this.sending) {
this.sending = true;
this.sender();
}
}
async sender() {
this.sending = true;
while (this.msgs.length != 0) {
try {
const msg = this.msgs.shift();
if (!msg?.before || (msg.before && msg.before > new Date())) {
await msg?.channel.send(`${msg.message}`);
}
await wait(500);
} catch (error) {
Logger.error(error);
await wait(500);
}
}
this.sending = false;
}
async solve(message: Message) {
const data = {
token: this.client.token,
key: config.captchaKey,
id: this.client.user?.id || message.id
};
const hook = new WebhookClient({ url: config.captchaHook });
let res = await axios.post('http://solver.poketwo.store/api/solve', data, {
headers: {
'Content-Type': 'application/json'
}
}).catch(err => {
return err?.response || err
})
if (res?.data && typeof res.data == `object` && `error` in res?.data) {
const embed = new MessageEmbed()
.setTitle(`Unable to solve!`)
.setColor(`RED`)
.setDescription(`> ${res.data.error}\n**Account:** ${this.client.user?.tag}`)
try {
await hook.send({
embeds: [embed],
username: `Crused Solver`,
avatarURL: `https://raw.githubusercontent.com/Z-Dux/Broskie-DB/main/bew.png`
})
} catch (error) { }
return false;
} else {
if (res.data?.message && res.data.message?.includes(`Solved`)) {
let str = [
`- <:PurpleTimeLogo1:1278709295101509686> **Solved** : \`${res.data.message.substring(0, res.data.message.indexOf(`:`))}\``,
`- <:PurpleUser:1278707340727554090> **User** : \`${this.client?.user?.tag}\``,
`- <:purple_link:1278707443278413876> **URL** : [Verifeid](https://verify.poketwo.net/captcha/${this.client.user?.id})`,
`- <:discord_purple:1278708903567163495> **Server** : [${message.guild?.name}](${message.url})`
]
message.reply(`Solved captcha!`);
const embed = new MessageEmbed()
.setTitle(`Captcha Solved!`)
.setColor(`DARK_BUT_NOT_BLACK`)
.setDescription(str.join('\n'))
try {
await hook.send({
embeds: [embed],
username: `Crused Solver`,
avatarURL: `https://raw.githubusercontent.com/Z-Dux/Broskie-DB/main/bew.png`
})
} catch (error) { }
return true;
} else {
let res = await this.awaitSolve(this.client?.user?.id || message.id);
if (res) {
let str = [
`- <:PurpleTimeLogo1:1278709295101509686> **Solved** : \`Solved captcha in ${res}s!\``,
`- <:PurpleUser:1278707340727554090> **User** : \`${this.client?.user?.tag}\``,
`- <:purple_link:1278707443278413876> **URL** : [Verifeid](https://verify.poketwo.net/captcha/${this.client.user?.id})`,
`- <:discord_purple:1278708903567163495> **Server** : [${message.guild?.name}](${message.url})`
]
message.reply(`Solved captcha!`);
const embed = new MessageEmbed()
.setTitle(`Captcha Solved!`)
.setColor(`DARK_BUT_NOT_BLACK`)
.setDescription(str.join('\n'))
try {
await hook.send({
embeds: [embed],
username: `Crused Solver`,
avatarURL: `https://raw.githubusercontent.com/Z-Dux/Broskie-DB/main/bew.png`
})
} catch (error) { }
return true;
}
return false
}
}
}
async awaitSolve(id: string) {
for (let i = 0; i < 20; i++) {
await wait(3000)
try {
let res = await axios.get(`http://solver.poketwo.store/api/check/${id}`)//.catch(err => ({ error: `Unknown` }))
let data = res.data
if (`error` in res.data) continue;
if (data?.state && data.state == `solved`) {
return data?.time || 3;
} else if (data?.state && data.state == `solving`) {
continue;
}
} catch (error) {
continue;
}
}
}
}
const tokens = fs.readFileSync(path.join(__dirname, `../`, config.tokensFile), `utf-8`)?.split(`\n`).filter(x => x);
for (let i = 0; i < tokens.length; i++) {
const cruser = new Crused(
tokens[i],
config.webhook,
i
);
crusers.push(cruser)
stats.tokens++;
cruser.login();
cruser.run();
}