forked from Pelellone/instagram-bot.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
executable file
·126 lines (114 loc) · 3.9 KB
/
bot.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
/**
* InstagramBot.js
* =====================
* Instagram Bot made with love and nodejs
*
* @author: Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)
* @file: bot.js
* @version: 0.7.4
*
* @license: Code and contributions have 'GNU General Public License v3'
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @link Homepage: https://instagram.bot.ptkdev.io
* GitHub Repo: https://github.com/social-manager-tools/instagram-bot.js
*/
/**
* Libs
* =====================
* Open source library
*
* @link: https://github.com/GoogleChrome/puppeteer
*
*/
var bot = null;
const puppeteer = require("puppeteer");
const config = require("./config");
const version = require("./version");
const LOG = require("./modules/logger/types");
async function start(bot, version, puppeteer, config, LOG) {
let browser = null;
/**
* Init
* =====================
* Set config options, check updates and integrity of bot
*
*/
let check = require("./modules/common/utils")(bot, config);
config = check.default_config(config);
check.donate();
check.check_updates(version.version);
if (config.executable_path === "" || config.executable_path === false) {
browser = await puppeteer.launch({
headless: config.chrome_headless,
args: config.chrome_options
});
} else {
browser = await puppeteer.launch({
headless: config.chrome_headless,
args: config.chrome_options,
executablePath: config.executable_path
});
}
bot = await browser.newPage();
/**
* Import libs
* =====================
* Modules of bot from folder ./modules
*
*/
let routes = require("./routes/strategies");
let utils = require("./modules/common/utils")(bot, config);
let Log = require("./modules/logger/Log");
let log = new Log("switch_mode");
let login = require("./modules/mode/login.js")(bot, config, utils);
let twofa = require("./modules/mode/2fa.js")(bot, config, utils);
/**
* Switch Mode
* =====================
* Switch social algorithms, change algorithm from config.js
*
*/
async function switch_mode() {
let strategy = routes[config.bot_mode];
if (strategy !== undefined) {
await strategy(bot, config, utils).start();
} else {
log(LOG.ERROR, "switch_mode", `mode ${strategy} not exist!`);
}
}
/**
* Start Bot (flow)
* =====================
* Login --> 2FA (bad location) --> 2FA (sms pin) --> social algorithm from config.js
*
*/
await login.start();
if (login.is_ok()) {
await twofa.start_twofa_location_check();
if (twofa.is_error()) {
await twofa.start_twofa_check();
}
if (twofa.is_ok()) {
await twofa.start_twofa_location();
} else if (twofa.is_ok_nextverify()) {
await twofa.start();
if (twofa.is_ok()) {
await switch_mode();
}
}else{
await switch_mode();
}
//await bot.close();
}
}
start(bot, version, puppeteer, config, LOG);