2022-11-30 16:43:49 +01:00
|
|
|
import fs = require('fs');
|
2022-12-01 21:53:29 +01:00
|
|
|
import {database as db,settings} from './database'
|
|
|
|
import prompt from 'prompts';
|
2022-11-30 15:04:45 +01:00
|
|
|
import logger from "./logger"
|
2022-11-30 16:43:49 +01:00
|
|
|
import * as telegram from 'telegram';
|
|
|
|
import { LogLevel } from 'telegram/extensions/Logger';
|
2022-11-30 19:23:04 +01:00
|
|
|
import { AccountInterface } from './interfaces/databaseInterface';
|
|
|
|
import { sleep } from 'telegram/Helpers';
|
|
|
|
import findFreePorts from 'find-free-ports';
|
2022-12-01 21:53:29 +01:00
|
|
|
import { waitNewMessages, startNewTorDocker, getIP } from './utils';
|
2022-11-30 15:04:45 +01:00
|
|
|
|
2022-11-30 16:43:49 +01:00
|
|
|
const addAccounts: ()=>Promise<void>=async ()=>{
|
|
|
|
let apiId: number=0
|
|
|
|
let apiHash: string= '';
|
|
|
|
let accounts=await db.getUsers();
|
|
|
|
if (accounts.length!=0){
|
|
|
|
const usePrevData=await prompt({
|
|
|
|
type: 'confirm',
|
|
|
|
name: 'confirmed',
|
|
|
|
message: 'Use apiId and apiHash from last added account?'
|
|
|
|
});
|
|
|
|
if (usePrevData.confirmed==true){
|
|
|
|
apiId=accounts[accounts.length-1].apiID;
|
|
|
|
apiHash=accounts[accounts.length-1].apiHash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (apiId==0 && apiHash==''){
|
|
|
|
const api=await prompt([
|
|
|
|
{
|
|
|
|
type:'number',
|
|
|
|
name:'apiId',
|
|
|
|
message:'ApiId?'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type:'text',
|
|
|
|
name:'apiHash',
|
|
|
|
message:'ApiHash?'
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
apiId=Number(api.apiId);
|
|
|
|
apiHash=api.apiHash;
|
|
|
|
}
|
|
|
|
let jsonFiles: prompt.Choice[]=[];
|
|
|
|
fs.readdirSync("./").forEach((file)=>{
|
|
|
|
if (file.search('.json')!=-1 && file!='db.json' && file!='settings.json'){
|
|
|
|
jsonFiles.push(
|
|
|
|
{
|
|
|
|
title: file,
|
|
|
|
description:'json file',
|
|
|
|
value:file,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const walletsFile=(await prompt({
|
|
|
|
type: 'select',
|
|
|
|
name: 'file',
|
|
|
|
message: 'Choose wallets json file',
|
|
|
|
choices: jsonFiles
|
|
|
|
})).file
|
|
|
|
await db.findWallet(walletsFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mainLoop:
|
|
|
|
while (true){
|
|
|
|
accounts=await db.getUsers();
|
|
|
|
const answers=await prompt([
|
|
|
|
{
|
|
|
|
type:'text',
|
|
|
|
name:'number',
|
|
|
|
message:'Phone number?'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type:'text',
|
|
|
|
name:'password',
|
|
|
|
message:'2FA Password?'
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
for (const account of accounts){
|
|
|
|
if (account.phoneNumber==answers.number){
|
|
|
|
logger.warn('You already added this number');
|
|
|
|
continue mainLoop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const session=new telegram.sessions.StringSession('');
|
|
|
|
const client=new telegram.TelegramClient(session,apiId,apiHash,{deviceModel:'Samsung SM-G980',connectionRetries: 5,systemVersion: '10'});
|
|
|
|
client.setLogLevel(LogLevel.ERROR);
|
|
|
|
await client.start({
|
|
|
|
phoneNumber: async ()=>answers.number.replace(/ /g, ""),
|
|
|
|
password: async ()=>answers.password.replace(/ /g, ""),
|
|
|
|
phoneCode: async () => (await prompt({
|
|
|
|
type:'number',
|
|
|
|
name:'code',
|
|
|
|
message:'Enter recieved code'
|
|
|
|
})).code.toString(),
|
|
|
|
onError: (err) => {
|
|
|
|
logger.error(`Error due singning into telegram account\n${err}`);
|
|
|
|
throw err
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if ((await client.isUserAuthorized())==true){
|
|
|
|
const account: telegram.Api.User | telegram.Api.InputPeerUser=(await client.getMe(false));
|
|
|
|
if (account instanceof telegram.Api.User ){
|
|
|
|
await db.addUser({
|
|
|
|
password: answers.password,
|
|
|
|
phoneNumber: answers.number,
|
|
|
|
apiHash: apiHash,
|
|
|
|
telegramID: Number(account.id),
|
|
|
|
apiID: apiId,
|
|
|
|
stringSession: String(client.session.save()),
|
|
|
|
refferal: await db.findRefferal(settings.maxRefferals)
|
|
|
|
},walletsFile)
|
|
|
|
} else {
|
|
|
|
logger.error("Wrong type of account?");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
logger.error('Client not authorized');
|
|
|
|
}
|
|
|
|
if ((await prompt({
|
|
|
|
type: 'confirm',
|
|
|
|
name: 'continue',
|
|
|
|
message: 'continue?'
|
|
|
|
})).continue!=true){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-11-30 15:04:45 +01:00
|
|
|
|
2022-11-30 16:43:49 +01:00
|
|
|
}
|
2022-11-30 15:04:45 +01:00
|
|
|
|
2022-11-30 19:23:04 +01:00
|
|
|
const farm: ()=>Promise<void>=async ()=>{
|
|
|
|
const proccesGroup=async (workers_group:AccountInterface[],ports: number[])=>{
|
2022-12-01 21:53:29 +01:00
|
|
|
const container=await startNewTorDocker(ports[0],ports[1],ports[2]);
|
2022-12-02 12:44:14 +01:00
|
|
|
console.log(0)
|
|
|
|
console.log(await getIP(ports[0]));
|
2022-12-01 21:53:29 +01:00
|
|
|
console.log(1)
|
2022-11-30 19:23:04 +01:00
|
|
|
for (const worker of workers_group){
|
|
|
|
logger.debug(`Current worker:${worker.phoneNumber}\nBalance:${worker.balance}`);
|
|
|
|
|
2022-12-01 21:53:29 +01:00
|
|
|
|
|
|
|
|
2022-11-30 19:23:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const workers=await db.getUsers();
|
|
|
|
let workers_groups: Array<AccountInterface[]>=[];
|
|
|
|
|
|
|
|
for (let i=0;i!=settings.pararels+1;i+=settings.pararels){
|
|
|
|
const _workers=workers.slice(i,i+settings.pararels);
|
|
|
|
if (_workers.length!=0){
|
|
|
|
workers_groups.push(_workers);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (workers_groups.length!=Math.ceil(workers.length/settings.pararels)){
|
|
|
|
logger.warn(`There is strange thing with workers_group\n${workers_groups.length} ${Math.ceil(workers.length/settings.pararels)}`);
|
|
|
|
}
|
|
|
|
let pararels: Promise<void>[] =[]
|
|
|
|
let _ports=await findFreePorts(settings.pararels*3);
|
|
|
|
for (let i=0;i!=settings.pararels;i++){
|
|
|
|
|
|
|
|
}
|
|
|
|
for (let i=0;i!=workers_groups.length;i++){
|
|
|
|
pararels.push(proccesGroup(workers_groups[i],_ports.slice(i*3,i*3+3)));
|
|
|
|
}
|
|
|
|
await Promise.all(pararels);
|
|
|
|
}
|
2022-11-30 15:04:45 +01:00
|
|
|
|
|
|
|
// menu
|
|
|
|
(async ()=> {
|
2022-11-30 16:43:49 +01:00
|
|
|
mainLoop:
|
2022-11-30 15:04:45 +01:00
|
|
|
while (true){
|
|
|
|
|
|
|
|
const answer=await prompt({
|
|
|
|
type: 'select',
|
|
|
|
name: 'menu',
|
|
|
|
message: 'Choose action',
|
|
|
|
choices: [
|
2022-11-30 16:43:49 +01:00
|
|
|
((await db.getUsers()).length>0) ? { title: 'Start',description: 'Starting farm', value: 'start' } : { title: 'Start',description: 'Add accounts first...', value: 'start' ,disabled: true},
|
2022-12-02 12:44:14 +01:00
|
|
|
{ title: 'Add accounts', description: 'Adds accounts', value: 'addAccounts' },
|
2022-11-30 15:04:45 +01:00
|
|
|
{ title: 'Check balances', value: 'checkBalances', disabled: true },
|
|
|
|
{ title: 'Withdraw', value: 'withdraw', disabled: true },
|
2022-11-30 16:43:49 +01:00
|
|
|
{ title: 'Exit',description: 'You realy dont know what it mean?'}
|
2022-11-30 15:04:45 +01:00
|
|
|
]
|
|
|
|
})
|
|
|
|
switch (answer.menu) {
|
|
|
|
case 'addAccounts':
|
2022-11-30 16:43:49 +01:00
|
|
|
await addAccounts();
|
2022-11-30 15:04:45 +01:00
|
|
|
break;
|
|
|
|
case 'start':
|
2022-11-30 19:23:04 +01:00
|
|
|
while (true){
|
|
|
|
try{
|
|
|
|
await farm();
|
|
|
|
} catch (err){
|
2022-12-01 21:53:29 +01:00
|
|
|
logger.error(`Unknown error\n${err}`)
|
2022-11-30 19:23:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-11-30 15:04:45 +01:00
|
|
|
break;
|
2022-11-30 19:23:04 +01:00
|
|
|
|
2022-11-30 15:04:45 +01:00
|
|
|
|
|
|
|
default:
|
2022-11-30 16:43:49 +01:00
|
|
|
logger.info('Bye bye');
|
|
|
|
break mainLoop;
|
2022-11-30 15:04:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})();
|