-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
177 lines (157 loc) · 6.82 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
import { Client } from "discord.js-selfbot-v13";
import readline from "readline";
import chalk from "chalk";
import dotenv from "dotenv";
import player from "play-sound";
import { spawn } from "child_process";
dotenv.config();
const args = process.argv.slice(2);
const client = new Client();
let playSound = args.includes("--sound=true");
// Global Variables
const gemItems = [];
let spam = false;
let activeChannel = null;
const gemTypeNames = { gem1: "Hunting Gem", gem3: "Empowering Gem", gem4: "Lucky Gem" };
const gemRarityNames = { c: "Common", u: "Uncommon", r: "Rare", e: "Epic", l: "Legendary", f: "Fable" };
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
// Utility Functions
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const randomWait = (min, max) => wait(Math.random() * (max - min + 1) * 1000 + min * 1000);
const playSoundEffect = (file) => playSound && player().play(file, (err) => err && console.error(err));
const log = (type, msg) => {
const chalkTypes = {
success: chalk.green,
warning: chalk.yellow,
error: chalk.red,
info: chalk.cyan
};
const logFunction = chalkTypes[type] || chalk.white;
console.log(logFunction(`[${type.toUpperCase()}]: ${msg}`));
};
const logDivider = (label) => console.log(chalk.blueBright(`\n${"=".repeat(60)}\n= ${label}${" ".repeat(Math.max(0, 58 - label.length))}=\n${"=".repeat(60)}\n`));
const superscriptMap = { "⁰": "0", "¹": "1", "²": "2", "³": "3", "⁴": "4", "⁵": "5", "⁶": "6", "⁷": "7", "⁸": "8", "⁹": "9" };
const convertSuperscriptToNumber = (str) => str.split("").map((char) => superscriptMap[char] || char).join("");
const restartProcess = async () => {
logDivider("STOPPING THE PROCESS");
log("warning", "Verification required. Stopping...");
playSoundEffect("./assets/157795.mp3");
await wait(2000);
const child = spawn(process.argv[0], process.argv.slice(1), { stdio: "inherit" });
child.on("close", (code) => {
log("error", `Process exited with code ${code}.`);
process.exit(code);
});
process.exit();
};
rl.on("line", (input) => {
const command = input.trim().toLowerCase();
if (command === "start") {
spam = true;
log("success", "Spam started.");
if (!activeChannel) log("warning", "Specify a channel by typing in a Discord channel first.");
} else if (command === "stop") {
spam = false;
log("warning", "Stopping the spam...");
} else {
log("error", "Unknown command. Use 'start' or 'stop'.");
}
});
client.on("ready", () => {
logDivider("OWOBOT FARMING SCRIPT");
log("success", `Logged in as ${client.user.username}`);
log("success", `Play Sound: ${playSound}`);
log("success", "Commands:\nstart : to start the spam.\nstop : to stop the spam. (note: it will still run the command one last time)");
});
client.on("messageCreate", async (message) => {
if (message.channel.type === "DM") return;
if (message.author.id === client.user.id) handleSelfCommands(message);
if (activeChannel && message.channel.id === activeChannel.id) handleOwOCommands(message);
});
const handleSelfCommands = (message) => {
if (message.content === "owo hh") {
activeChannel = message.channel;
spam = true;
log("success", "Channel set and spam started.");
} else if (message.content === "owo bb") {
spam = false;
log("warning", "Stopping the spam...");
} else if (!activeChannel) {
activeChannel = message.channel;
log("success", `Channel set to #${activeChannel.name}.`);
}
};
const handleOwOCommands = async (message) => {
const myself = message.guild.members.me?.nickname || client.user.displayName;
if (message.content.includes(`**====== ${myself}'s Inventory ======**`)) {
log("info", "Parsing inventory...");
parseInventory(message.content);
}
if (message.author.id === "408785106942164992") {
if (message.cleanContent.includes(`**🌱 | ${myself}**, hunt`)) {
await processHuntAndBattle(message);
} else if (message.components.length && message.components[0].components[0].label === "Verify") {
spam = false;
restartProcess();
}
}
};
const parseInventory = (content) => {
const regex = /`(\d+)`(<:|<a:)(cgem|ugem|rgem|egem|lgem|fgem)(\d+):\d+>(\W{2})/g;
let result;
while ((result = regex.exec(content)) !== null) {
const [id, rarityKey, typeKey, amount] = [parseInt(result[1]), result[3].charAt(0), `gem${result[4]}`, parseInt(convertSuperscriptToNumber(result[5]))];
gemItems.push({ id, type: gemTypeNames[typeKey] || typeKey, rarity: gemRarityNames[rarityKey] || rarityKey, amount });
}
log("success", "Inventory parsed successfully.");
console.table(gemItems, ["id", "type", "rarity", "amount"]);
};
const processHuntAndBattle = async (message) => {
logDivider("HUNT AND BATTLE");
if (!gemItems.length) {
activeChannel.sendTyping();
await randomWait(1, 3);
activeChannel.send("owo inv");
}
const gemAmounts = extractGemsLeft(message.content);
log("info", "Gems Remaining:");
console.table(gemAmounts);
await handleMissingGems(gemAmounts);
if (spam) await spamHuntAndBattle();
};
const extractGemsLeft = (content) => {
const gemAmounts = { "Hunting Gem": 0, "Empowering Gem": 0, "Lucky Gem": 0 };
const regex = /(gem1|gem3|gem4):\d+>`\[(\d+)/g;
let result;
while ((result = regex.exec(content)) !== null) {
gemAmounts[gemTypeNames[result[1]] || result[1]] = parseInt(result[2]);
}
return gemAmounts;
};
const sendCommandWithRandomWait = async (command) => {
activeChannel.sendTyping();
await randomWait(1, 2);
activeChannel.send(command);
};
const handleMissingGems = async (gemAmounts) => {
for (const [gemType, amount] of Object.entries(gemAmounts)) {
if (amount === 0) {
log("warning", `${gemType} has no remaining amount.`);
const highestIdGem = gemItems.filter((gem) => gem.type === gemType && gem.amount > 0).reduce((highest, current) => (current.id > highest.id ? current : highest), {});
if (highestIdGem.id) {
await sendCommandWithRandomWait(`owo use ${highestIdGem.id}`);
highestIdGem.amount -= 1;
log("success", `Used ${highestIdGem.rarity} ${highestIdGem.type} (ID: ${highestIdGem.id}). Remaining: ${highestIdGem.amount}`);
}
}
}
};
const spamHuntAndBattle = async () => {
logDivider("SPAMMING COMMANDS");
await randomWait(15, 20);
await sendCommandWithRandomWait("owo h");
await sendCommandWithRandomWait("owo b");
log("success", "Commands sent successfully.");
if (!spam) log("success", "Successfully stopped the spam.");
};
client.login(process.env.TOKEN);