forked from erichlotto/yieldly-compounder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aocean.js
111 lines (92 loc) · 4 KB
/
aocean.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
const puppeteer = require("puppeteer");
const readline = require("readline");
const settings = require("./settings");
const axios = require('axios');
////////////////////////////////////////////
// //
// DISCORD GROCERY COMMANDS //
// PLEASE CHECK settings.js //
// //
////////////////////////////////////////////
const DACCOUNT = settings.daccount;
const DPW = settings.dpw;
const DCOMMAND = '$work';
// RPI4 Settings
const PUPPETEER_SETTINGS = {
headless: settings.headless,
executablePath: '/usr/bin/chromium-browser',
args: ['--single-process', '--no-zygote', '--no-sandbox', '--disable-setuid-sandbox'],
userDataDir: "./user_data"
};
const ENTER = String.fromCharCode(13);
const TAB = String.fromCharCode(9);
const ESC = String.fromCharCode(27);
let browser;
// CONNECTS DISCORD
const connectDiscord = async browser => {
let pages = await browser.pages();
const discordPage = pages[0];
await discordPage.waitForTimeout(10000);
// log(`--- Check if account is logged in ---`);
// CHECKS IF THERE'S AN <input name=password> IN PAGE, INDICATING ACCOUNT NOT LOGGED IN
const accNotLoggedIn = await discordPage.evaluate(
() => !!document.querySelector("input[name='password']")
) // !! converts anything to boolean
if (accNotLoggedIn) {
log(`--- Logging in account ---`);
await discordPage.waitForTimeout(1000);
await discordPage.waitForSelector("input[name='password']");
await discordPage.type("input[name='email']", [DACCOUNT]);
await discordPage.waitForTimeout(1000);
await discordPage.type("input[name='password']", [DPW, ENTER]);
await discordPage.waitForTimeout(1000);
log(`--- Logged in ---`);
} else {
log(`--- Logged in ---`);
}
}
// PAUSE EXECUTION FOR THE SPECIFIED AMOUNT OF TIME
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
// LOGS OUTPUT TO CONSOLE AND (OPTIONALLY) TO TELEGRAM, IF VARIABLES ARE PRESENT IN SETTINGS.JS
const log = message => {
console.log(message);
settings.telegram_api && settings.telegram_chatid &&
axios.get(`https://api.telegram.org/bot${settings.telegram_api}/sendmessage?chat_id=${settings.telegram_chatid}&disable_web_page_preview=1&disable_notification=true&text=${encodeURIComponent(message)}`);
}
// RUNS THIS SCRIPT
(async () => {
for (let i = 0; i < 3; i++) { // TRY TO RUN THE SCRIPT 3 TIMES TO BYPASS POSSIBLE NETWORK ERRORS
try {
log(`------ START -----`);
log(`DISCORD AOCean Every 3 hours command $work`);
browser = await puppeteer.launch(PUPPETEER_SETTINGS);
let pages = await browser.pages();
const discordPage = pages[0];
// log(`--- Loading ---`);
await discordPage.goto('https://discord.com/channels/896603438790627328/905493823034097725');
await discordPage.waitForTimeout(15000);
await discordPage.setViewport({ width: 1366, height: 768});
await connectDiscord(browser);
await discordPage.waitForTimeout(15000);
// *******************
// SEND COMMAND
// *******************
await discordPage.waitForSelector('[data-can-focus="true"]');
await discordPage.click('[data-can-focus="true"]');
await discordPage.type('[data-slate-object="block"]', [DCOMMAND]);
await discordPage.type('[data-slate-object="block"]', [ENTER]);
await discordPage.waitForTimeout(1000);
await discordPage.type('[data-can-focus="true"]', [ENTER]);
await discordPage.type('[data-can-focus="true"]', [ENTER]);
log(`--- Command sent ---`);
// Close out
await sleep(10000);
await browser.close();
log(`------ END -----`);
break;
} catch (e) {
await browser.close();
log(`ERROR: ${e}\n`)
}
}
})();