-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
136 lines (113 loc) · 3.88 KB
/
index.js
File metadata and controls
136 lines (113 loc) · 3.88 KB
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
/*
* OwO Farm Bot Stable / https://github.com/Mid0Hub/owofarmbot_stable/blob/main/utils/autovote.js
* Copyright (C) 2024 Mido
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/
/*
* autovoter for top.gg
*/
const packageJson = require("./package.json");
const cp = require("child_process");
const path = require("path");
const fse = require("fs-extra");
for (let dep of Object.keys(packageJson.dependencies)) {
try {
require.resolve(dep);
} catch (err) {
console.log("Installing dependencies...");
cp.execSync(`npm i`);
}
}
const { connect } = require("puppeteer-real-browser");
const yargs = require("yargs");
const argv = yargs.options({
token: {
alias: "t",
describe: "User token",
type: "string",
demandOption: true,
},
botid: {
alias: "bid",
describe: "Id of the bot to vote for",
type: "string",
demandOption: true,
},
}).argv;
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const adblockcachedir = path.resolve(__dirname, "./adblockcache");
if (!fse.existsSync(adblockcachedir)) {
fse.mkdirSync(adblockcachedir, { recursive: true });
}
(async () => {
const topcici = "https://top.gg";
const { token, botid } = argv;
const { browser, page } = await connect({
headless: false,
turnstile: true,
plugins: [
require("puppeteer-extra-plugin-adblocker")({
blockTrackers: true,
useCache: true,
cacheDir: adblockcachedir,
}),
],
});
await page.setViewport({
width: 1920,
height: 1080,
});
await page.evaluateOnNewDocument((token) => {
window.localStorage.setItem("token", `"${token}"`);
}, token);
await page.goto(topcici, { waitUntil: "load" });
await page.waitForSelector(".chakra-button.css-7rul47", { visible: true });
await page.locator(".chakra-button.css-7rul47").setTimeout(3000).click();
// Discord auth
await page.waitForNavigation({ waitUntil: "load" });
await page.waitForSelector("div.action__3d3b0 button", { visible: true });
await page.locator("div.action__3d3b0 button").setTimeout(3000).click();
await page.waitForNavigation({ waitUntil: "load" });
await delay(5000);
const isLoggedIn = await page.evaluate(() => {
return !document.body.innerText.includes("Login");
});
if (isLoggedIn) {
let topgglink = `https://top.gg/bot/${botid}/vote`;
await page.goto(topgglink, { waitUntil: "load" });
while (true) {
const isAlreadyVoted = await page.evaluate(() => {
return document.body.innerText.includes(
"You have already voted",
);
});
const isvoteable = await page.evaluate(() => {
return document.body.innerText.includes("You can vote now!");
});
if (isAlreadyVoted) {
console.log("You have already voted. Exiting...");
await browser.close();
process.exit(0);
}
if (isvoteable) {
break;
} else {
await delay(2500);
}
}
await page.evaluate(() => {
const button = document.querySelector(
"div.css-1yn6pjb button.chakra-button.css-7rul47",
);
if (!button || button.disabled) {
return;
}
button.click();
});
await delay(5000);
} else {
console.log("Authorization failed.");
}
await browser.close();
})();