Archived
1
0
This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
Slavesbot/bot.js

305 lines
9.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const DEF_DELAY = 1200;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms || DEF_DELAY));
}
const got = require('got');
const { whitelist, user_agent, origin } = require('./config');
module.exports = function (users) {
for (const user of users){
var a = new SlaveMaster(user);
a.start()
}
};
class SlaveMaster{
my_id = -1;
balance = 0;
friends = [];
slaves_already = [];
constructor(user) {
this.name = user.name;
this.token = user.token;
this.job = user.job;
this.buy_slaves = user.buy_slaves;
this.buy_fetters = user.buy_fetters;
this.upgrade_slaves = user.upgrade_slaves;
this.min_fetter_profit = user.min_fetter_profit;
this.min_balance = user.min_balance;
this.min_price = user.min_price;
this.max_price = user.max_price;
this.min_upgrade_price = user.min_upgrade_price;
this.getFriendsIds = user.getFriendsIds;
}
async start(){
try {
await this.init();
console.log(this.name,' ||| ','Авторизация прошла успешно');
var response = await this.getMyInfo();
this.my_id = response.me.id;
this.balance = response.me.balance;
console.log(this.name,' ||| ','Мой владелец ',response.me.master_id);
console.log(this.name,' ||| ','Бот был запущен');
await sleep();
this.checkFetter();
this.getFriends();
this.buySlaves();
} catch(err) {
console.error(err);
console.error(err.response.body);
}
}
async init(){
try {
var bearer_response = await got.get(`https://api.vk.com/method/apps.get?app_id=7794757&platform=ios&access_token=${this.token}&v=5.23`, {
headers: {
'user-agent': user_agent
},
throwhttperrors: true,
responseType: 'json',
resolveBodyOnly: true
}).json();
var url = bearer_response.response.mobile_iframe_url;
var bearer = 'Bearer ' + url.substring(url.indexOf('index.html?')).substring(11);
this.authorization = bearer;
} catch(error) {
console.error(error);
console.error(this.name,' --- ','Ошибка Авторизации: ',error.response.body);
}
setTimeout(() => {this.init()},600000);
}
async getFriends(){
try {
var friends_response = await got.get(`https://vk-api-proxy.xtrafrancyz.net/method/friends.get?user_id=${this.my_id}&count=10000&access_token=${this.token}&v=5.150`).json();
this.friends = friends_response.response.items;
await sleep();
//users.getFollowers
for await (const id of this.getFriendsIds){
var friends_response1 = await got.get(`https://vk-api-proxy.xtrafrancyz.net/method/friends.get?user_id=${id}&count=20000&access_token=${this.token}&v=5.150`).json();
var friends_array1 = friends_response1.response.items;
for await (const friend of friends_array1){
await this.friends.push(friend);
}
var friends_response2 = await got.get(`https://vk-api-proxy.xtrafrancyz.net/method/users.getFollowers?user_id=${id}&count=1000&access_token=${this.token}&v=5.150`).json();
var friends_array2 = friends_response2.response.items;
for await (const friend of friends_array2){
await this.friends.push(friend);
}
await sleep();
}
console.log(this.name,' --- ','Друзей: ',this.friends.length);
} catch(error) {
console.error(this.name,' --- ','Ошибка получения списка друзей: ',error);
}
await sleep(300000);
this.getFriends();
}
async getMyInfo(){
var response = await got.get(`https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/start`, {
headers: {
'user-agent': user_agent,
'authorization' : this.authorization,
'Origin': origin
}
}).json();
await sleep(100);
return response;
}
async getInfo(id){
var response = await got.get(`https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/user?id=${id}`, {
headers: {
'user-agent': user_agent,
'authorization' : this.authorization,
'Origin': origin
}
}).json();
await sleep(100);
return response;
}
async buySlave(slave){
await got.post(`https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/buySlave`, {
headers: {
'user-agent': user_agent,
'authorization' : this.authorization,
'Origin': origin
},
throwhttperrors: true,
responseType: 'json',
resolveBodyOnly: true,
json: {
slave_id: slave.id
}
}).then((response)=>{
this.balance = response.balance;
this.slaves_already.push(slave.id);
console.log(this.name,' ||| ','Новый раб \tid:',slave.id,' \tЦена:',slave.price);
}).catch(async (error) => {
await sleep();
console.error(this.name,' --- ','Ошибка покупки раба: ',error.response.body/*.replace(/(\<.*?\>)/g, '')*/);
});
await sleep();
}
async sellSlave(slave){
await got.post(`https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/saleSlave`, {
headers: {
'user-agent': user_agent,
'authorization' : this.authorization,
'Origin': origin
},
throwhttperrors: true,
responseType: 'json',
resolveBodyOnly: true,
json: {
slave_id: slave.id
}
}).then((response)=>{
this.balance = response.balance;
this.slaves_already.push(slave.id);
console.log(this.name,' ||| ','Продан раб \tid:',slave.id);
}).catch(async (error) => {
console.error(this.name,' --- ','Ошибка продажи раба: ',error.response.body/*.replace(/(\<.*?\>)/g, '')*/);
});
await sleep();
}
async jobSlave(slave){
await got.post(`https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/jobSlave`, {
headers: {
'user-agent': user_agent,
'authorization' : this.authorization,
'Origin': origin
},
throwhttperrors: true,
responseType: 'json',
resolveBodyOnly: true,
json: {
slave_id: slave.id,
name: this.job
}
}).then((response)=>{
console.log(this.name,' ||| ','Новая работа \tid:',slave.id,' \tПрибыль в минуту:',response.slave.profit_per_min);
}).catch(async (error) => {
await sleep();
console.error(this.name,' --- ','Ошибка при устройстве на работу: ',error.response.body/*.replace(/(\<.*?\>)/g, '')*/);
});
await sleep();
}
async buyFetter(slave,nums){
await got.post(`https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/buyFetter`, {
headers: {
'user-agent': user_agent,
'authorization' : this.authorization,
'Origin': origin
},
throwhttperrors: true,
responseType: 'json',
resolveBodyOnly: true,
json: {
slave_id: slave.id
}
}).then((response)=>{
// balance = response.balance;
this.balance -= slave.fetter_price;
console.log(this.name,' ||| ','Купил цепь \tid:',slave.id,'\tЦена:',slave.fetter_price,'\tПрибыль принесет:',(slave.profit_per_min*60*2-slave.fetter_price));
}).catch(async (error) => {
await sleep();
var err=""+error.response.body;
console.error(this.name,' --- ','Ошибка покупки кандалов: ',error.response.body/*.replace(/(\<.*?\>)/g, '')*/);
});
await sleep();
}
async checkFetter(){
try {
var response = await this.getMyInfo();
// console.log(response.me);
this.balance = response.me.balance;
console.log(this.name,' =|= ',"Текущий баланс: ",response.me.balance,' \tРабов: ',response.me.slaves_count,'\tДоход в минуту: ',response.me.slaves_profit_per_min,' \tМесто в рейтинге: ',response.me.rating_position);
var slaves_array = [];
var slaves = response.slaves;
for await (const slave of slaves){
if(((slave.profit_per_min>this.min_fetter_profit&&slave.fetter_price<=120000)||whitelist.includes(slave.id))&&slave.fetter_to==0&&slave.fetter_price<=this.balance&&this.buy_fetters){
await this.buyFetter(slave);
}
}
for await (const slave of slaves){
slaves_array.push(slave.id);
if(((slave.profit_per_min>1&&slave.fetter_price<=120000)||whitelist.includes(slave.id))&&slave.fetter_to==0&&slave.fetter_price<=this.balance&&this.buy_fetters){
await this.buyFetter(slave);
}
if(slave.profit_per_min==0){
await this.jobSlave(slave);
}
}
this.slaves_already = slaves_array;
} catch(error) {
console.error(this.name,' --- ','Ошибка проверки кандалов: ',error);
}
await sleep(5000);
this.checkFetter();
}
async buySlaves(){
if(this.buy_slaves) try {
var friends_ids = this.friends.filter( ( friend ) => !this.slaves_already.includes( friend ) );
for await (const friend of friends_ids){
var slave = await this.getInfo(friend);
if(slave.master_id!=this.my_id&&this.balance>=this.min_balance&&this.balance>=slave.price&&slave.price<=this.max_price&&slave.price>=this.min_price&&slave.fetter_to==0){
await this.buySlave(slave);
}
}
await this.upgradeSlaves();
await sleep(5000);
this.buySlaves();
} catch(error) {
console.error(this.name,' --- ','Ошибка покупки рабов: ',error);
await sleep(5000);
this.buySlaves();
}
}
async upgradeSlaves(){
if(this.upgrade_slaves) try {
var response = await this.getMyInfo();
for await (const slave of response.slaves){
if(this.balance>=1000000&&slave.price<=27000&&slave.price>=this.min_upgrade_price){
await this.sellSlave(slave);
await sleep(100);
await this.buySlave(slave);
await sleep(100);
}
}
return;
} catch(error) {
console.error(this.name,' --- ','Ошибка улучшения рабов: ',error);
}
}
}