some changes

This commit is contained in:
”minicx” 2022-12-02 18:41:38 +03:00
parent cb3b1c71fa
commit 8ab8d0363f
7 changed files with 130 additions and 24 deletions

9
automatization.ts Normal file
View File

@ -0,0 +1,9 @@
import Hero from "@ulixee/hero";
import { AccountInterface } from "./interfaces/databaseInterface";
export const vertification=async function vertification(worker: AccountInterface,hero: Omit<Hero, "then">,url: string) {
await hero.goto(url);
await hero.waitForLoad('AllContentLoaded');
}

View File

@ -57,8 +57,8 @@ export class Database {
return faucetWallet;
}
async findRefferal(maxRefferals: number): Promise<number | boolean>{
let refferal: number | boolean=false;
async findRefferal(maxRefferals: number): Promise<number | null>{
let refferal: number | null=null;
const accounts=(await this.getUsers());
if (accounts.length>0){
for (const mainAccount of accounts){
@ -140,24 +140,24 @@ export class Database {
export class Settings implements interfacesSettings.settingsInterface {
public readonly default: interfacesSettings.settingsInterface={
logLevel: 'debug',
pararels:2,
pararels: 2,
mainCrypto: 'TRX',
minimalToWithdraw: 0.0003,
maxRefferals: 3,
botMessages:{
verification:'To continue using this bot,',
tasksSelector:'Choose an option to start earning your TRX',
botMessages: {
verification: 'To continue using this bot,',
tasksSelector: 'Choose an option to start earning your TRX',
},
botButtons:{
earn:'❇️ Earn cryptocurrency',
balance:'💰 Balance',
withdraw:'📤 Withdraw'
botButtons: {
earn: '❇️ Earn cryptocurrency',
balance: '💰 Balance',
withdraw: '📤 Withdraw'
},
telegramLinks:{
botLink:'@hkearn_trx_bot',
groupsToJoin:['@hkearn_transactions','@hkearn_updates']
}
telegramLinks: {
botLink: '@hkearn_trx_bot',
groupsToJoin: ['@hkearn_transactions', '@hkearn_updates']
},
bypassMode: false
}
logLevel: "debug" | "info" | "error";
mainCrypto: "TRX";
@ -166,6 +166,8 @@ export class Settings implements interfacesSettings.settingsInterface {
botMessages: { verification: string; tasksSelector: string; };
botButtons: { earn: string; balance: string; withdraw: string; };
telegramLinks: { botLink: string; groupsToJoin: string[]; };
bypassMode: boolean
pararels: number
private json: JsonDB;
constructor (){
this.json=new JsonDB(new Config('settings.json',true,true,'/'));
@ -186,7 +188,7 @@ export class Settings implements interfacesSettings.settingsInterface {
}
});
}
pararels: number
}

View File

@ -7,10 +7,12 @@ import { LogLevel } from 'telegram/extensions/Logger';
import { AccountInterface } from './interfaces/databaseInterface';
import { sleep } from 'telegram/Helpers';
import findFreePorts from 'find-free-ports';
import { waitNewMessages, startNewTorDocker, getIP } from './utils';
import { waitNewMessages, startNewTorDocker, getIP,getMessagesByEntity} from './utils';
import {connect, disconnect, tor} from "node-tor-control";
import Miner from '@ulixee/miner';
import Hero from '@ulixee/hero';
import {ipInterface} from "./interfaces/otherInterfaces"
import { vertification } from './automatization';
const addAccounts: ()=>Promise<void>=async ()=>{
let apiId: number=0
@ -136,13 +138,13 @@ const farm: ()=>Promise<void>=async ()=>{
const proccesGroup=async (workers_group:AccountInterface[],ports: number[])=>{
const container=await startNewTorDocker(ports[0],ports[1],ports[2]);
const ip={
prev:'',
const ip: ipInterface={
prev:[''],
current:''
}
for (const worker of workers_group){
logger.debug(`Current worker:${worker.phoneNumber}\nBalance:${worker.balance}`);
while (ip.prev==ip.current){
while (ip.prev.indexOf(ip.current)!=-1){
const torConnection = await connect({
host: '127.0.0.1',
port:ports[2],
@ -151,6 +153,7 @@ const farm: ()=>Promise<void>=async ()=>{
await tor.signalNewNYM(torConnection);
ip.current=(await getIP(ports[0]))!;
}
ip.prev.push(ip.current)
const miner = new Miner();
await miner.listen({port: ports[-1]});
const fingerprint=worker.browserFingerprint
@ -167,18 +170,93 @@ const farm: ()=>Promise<void>=async ()=>{
connectionToCore: { host:`ws://${await miner.address}` },
disableDevtools: true, // to bypass hk site
showChrome:true, // to debug
showChromeInteractions:true,
userAgent:fingerprint.navigator.userAgent,
viewport:fingerprint.screen,
locale:fingerprint.navigator.language,
upstreamProxyUrl:`socks5://127.0.0.1:${ports[1]}`,
});
break;
} catch (err){
logger.warn(`Some error due openning Hero. Trying again...\n${err}`);
continue
}
}
const client=new telegram.TelegramClient(
new telegram.sessions.StringSession(worker.stringSession),
worker.apiID,
worker.apiHash,
{deviceModel:'Samsung SM-G980',connectionRetries: 5,systemVersion: '10'}
);
client.setLogLevel(LogLevel.ERROR);
await client.connect();
if ((await client.checkAuthorization())==false){
logger.error(`Account ${worker.phoneNumber} is not authorizated`);
continue
} else {
logger.debug(`Successfully connected to account ${worker.phoneNumber}`);
// https://gram.js.org/beta/modules/Api.channels.html
// https://gram.js.org/beta/classes/Api.messages.DeleteChat.html
const botEntity=await client.getEntity(settings.telegramLinks.botLink) as telegram.Api.User;
for (const chat of settings.telegramLinks.groupsToJoin){
try{
await client.invoke(new telegram.Api.channels.GetParticipant({channel:chat,participant:'me'}));
} catch(err){
if (err.code==400){
await client.invoke(new telegram.Api.channels.JoinChannel({channel:chat}));
} else{
logger.error(`${worker.phoneNumber} | Unknown error due GetParticipant`)
throw err;
}
}
}
if ((await getMessagesByEntity(client,botEntity,botEntity)).length==0){
if (worker.refferal!==null){
await client.sendMessage(botEntity,{message:`/start ${worker.refferal}`});
logger.debug(`${worker.phoneNumber} | First start of ${botEntity.username} via refferal link of ${worker.refferal}`);
}else {
await client.sendMessage(botEntity,{message:`/start`});
logger.debug(`${worker.phoneNumber} | First start of ${botEntity.username}`);
}
logger.info(`${worker.phoneNumber} | Sending earn message...`);
const requestTasksMessage=await client.sendMessage(botEntity,{message:settings.botButtons.earn});
await waitNewMessages(client,worker,botEntity,requestTasksMessage.id)
let tasksSelector:telegram.Api.Message;
try {
tasksSelector=(await client.getMessages(botEntity,{
minId:requestTasksMessage.id,
search: settings.botMessages.tasksSelector,
}))[0];
} catch (err){
try{
tasksSelector=(await client.getMessages(botEntity,{
minId:requestTasksMessage.id,
search: settings.botMessages.verification,
}))[0];
const url: string=tasksSelector.buttons![0][0].url!;
await vertification(worker,hero,url);
} catch (err){
logger.error(`Check ${worker.phoneNumber} for last message`);
throw new Error("Unknow message was found");
}
}
}
}
}

View File

@ -29,7 +29,7 @@ export interface AccountInterface {
completedGroupsTasks:AccountCompletedGroupsTasksInterface[],
canBeRefferal: boolean,
browserFingerprint:Fingerprint,
refferal:number | boolean
refferal:number | null
}
export interface DatabaseInterface {

4
interfaces/otherInterfaces.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
export interface ipInterface {
prev: string[],
current: string
}

View File

@ -21,6 +21,7 @@ export interface settingsInterface {
botLink: string,
groupsToJoin: string[]
}
},
bypassMode: boolean
}

View File

@ -10,6 +10,18 @@ import * as telegram from 'telegram';
import axios from "axios";
import ProgessBar from "progress"
export const getMessagesByEntity=async function(client:telegram.TelegramClient,chatEntity:telegram.Api.Chat | telegram.Api.User,entity: telegram.Api.User | telegram.Api.User,params={}){
var messages=new telegram.helpers.TotalList<telegram.Api.Message>;
for (const message of await client.getMessages(chatEntity,params)){
if ((message.sender as telegram.Api.User).username==entity.username){
messages.push(message);
}
}
return messages;
}
export const getIP=async function (proxyPort: number): Promise<string | null> {
// const res=await shttps.get({
// url: 'icanhazip.com',
@ -30,7 +42,7 @@ export const getIP=async function (proxyPort: number): Promise<string | null> {
return data
}
export const waitNewMessages=async function(client: telegram.TelegramClient,worker: AccountInterface,chatEntity,idOfLastMessage: number,timeout: number=20): Promise<void>{
export const waitNewMessages=async function(client: telegram.TelegramClient,worker: AccountInterface,chatEntity: telegram.Api.Chat | telegram.Api.User,idOfLastMessage: number,timeout: number=20): Promise<void>{
const start_time=new Date();
while ((await client.getMessages(chatEntity,{minId:idOfLastMessage})).length==0){