Merge pull request from playground

Reviewed-on: #10
This commit is contained in:
minicx 2022-12-14 17:58:32 +00:00
commit 0c7f8c9e6c
12 changed files with 1824 additions and 1086 deletions

2
.gitignore vendored
View File

@ -10,4 +10,4 @@ data.json
settings.json
yarn-error.log
yarn.lock
db.json1
db.json1

23
LICENSE Normal file
View File

@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright (c) Minicx and Contributors
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

57
README.md Normal file
View File

@ -0,0 +1,57 @@
<div align="center">
<h1><b>HK_BOT🤖</b></h1>
<a href="https://hits.sh/git.disroot.org/minicx/hk_bot/"><img alt="Hits" src="https://hits.sh/git.disroot.org/minicx/hk_bot.svg"/></a>
<a href="https://git.disroot.org/minicx/hk_bot/LiCENSE"><img src="https://shields.io/badge/license-MIT-green" alt='License'/></a>
</div>
# Installing
1. #### Cloning repo
To do this run `git clone https://git.disroot.org/minicx/hk_bot.git`
2. #### Installing all dependencies
Run in `hk_bot` directory `npm install` or `yarn install`
3. #### Starting
Run `npm start` or `yarn start`
<details>
<summary>Other commands</summary>
| Command | Description |
| ------- | ------------------------------------------------------------------ |
| build | just compile all `.ts` files to `build` directory into `.js` |
</details>
# Format of [Faucet](https://faucetpay.io) wallets data
* **❗ The script currently does not use the email or password of the faucet account ❗**
* **JSON file must be in root of `hk_bot` directory**
* <details>
<summary><b>Explanation.json</b></summary>
```json
{
"<EMAIL>": {
"mail_passphrase": "<PASSWORD OF MAIL>",
"faucetpay": {
"username": "<USERNAME OF FAUCET ACCOUNT>",
"password": "<PASSWORD OF FAUCET ACCOUNT>"
}
}
}
```
</details>
# Creator and contributors
<div align='center'>
<img src="https://git.disroot.org/avatars/cf8b3507d9ab93a478052ffd7e750f12" width="100px" style="display:flex;border-radius: 75px;" alt="minicx_pict" >
<a href="https://git.disroot.org/minicx"><b>Main devoloper</b></a>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -1,237 +1,272 @@
import {JsonDB,Config} from "node-json-db"
import {FingerprintGenerator} from "fingerprint-generator"
import logger from "./logger"
import * as interfacesDB from "./interfaces/databaseInterface"
import * as interfacesSettings from "./interfaces/settingsInterface"
import { arrayWithoutElementAtIndex } from "./utils"
import { JsonDB, Config } from "node-json-db";
import { FingerprintGenerator } from "fingerprint-generator";
import logger from "./logger";
import * as interfacesDB from "./interfaces/databaseInterface";
import * as interfacesSettings from "./interfaces/settingsInterface";
import { arrayWithoutElementAtIndex } from "./utils";
export class Database {
public readonly default: interfacesDB.DatabaseInterface={
accounts:[]
}
public readonly default: interfacesDB.DatabaseInterface = {
accounts: [],
};
private json: JsonDB;
constructor (){
this.json=new JsonDB(new Config('db.json',false,true,'/'));
this.json.getData('/').then((result)=>{
if (Object.keys(result).length==0){
this.json.push('/',this.default,true)
.catch((err) => logger.error(`${err} due setting defaults`))
.then(() => {
logger.info('Setting DB to defaults...');
});
constructor() {
this.json = new JsonDB(new Config("db.json", false, true, "/"));
this.json.getData("/").then((result) => {
if (Object.keys(result).length == 0) {
this.json
.push("/", this.default, true)
.catch((err) => logger.error(`${err} due setting defaults`))
.then(() => {
logger.info("Setting DB to defaults...");
});
this.save();
}
})
});
}
async findWallet(walletsFile: string): Promise<interfacesDB.faucetMailInterface | undefined>{
const wallets_json=new JsonDB(new Config(walletsFile,true,true,'/'));
const wallets=(await wallets_json.getData('/'));
if (Object.keys(wallets).length==0){
logger.error('File which you choose doesnt have anything');
throw new Error('File which you choose doesnt have anything')
}
const accounts=(await this.getUsers());
let faucetWallet:interfacesDB.faucetMailInterface | undefined=undefined;
for (const _wallet in wallets){
let flag=false;
if (accounts.length>0){
for (const account of accounts){
if (account.faucetMail.mail.address==_wallet ){
flag=true;
async findWallet(
walletsFile: string
): Promise<interfacesDB.faucetMailInterface | undefined> {
const wallets_json = new JsonDB(
new Config(walletsFile, true, true, "/")
);
const wallets = await wallets_json.getData("/");
if (Object.keys(wallets).length == 0) {
logger.error("File which you choose doesnt have anything");
throw new Error("File which you choose doesnt have anything");
}
const accounts = await this.getUsers();
let faucetWallet: interfacesDB.faucetMailInterface | undefined =
undefined;
for (const _wallet in wallets) {
let flag = false;
if (accounts.length > 0) {
for (const account of accounts) {
if (account.faucetMail.mail.address == _wallet) {
flag = true;
break;
}
}
}
if (flag==false){
faucetWallet={
if (flag == false) {
faucetWallet = {
faucet: {
username:wallets[_wallet].faucetpay.username,
password:wallets[_wallet].faucetpay.password
username: wallets[_wallet].faucetpay.username,
password: wallets[_wallet].faucetpay.password,
},
mail: {
address:_wallet,
password:wallets[_wallet].mail_passphrase
}
}
address: _wallet,
password: wallets[_wallet].mail_passphrase,
},
};
break;
}
}
return faucetWallet;
}
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){
let counter=0;
if (mainAccount.canBeRefferal==true){
let _accounts=arrayWithoutElementAtIndex(accounts,accounts.indexOf(mainAccount));
for (const _account of _accounts){
if (_account.refferal==mainAccount.telegramID){
counter+=1;
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) {
let counter = 0;
if (mainAccount.canBeRefferal == true) {
const _accounts = arrayWithoutElementAtIndex(
accounts,
accounts.indexOf(mainAccount)
);
for (const _account of _accounts) {
if (_account.refferal == mainAccount.telegramID) {
counter += 1;
}
}
if (counter<maxRefferals){
refferal=Number(mainAccount.telegramID);
}
if (counter < maxRefferals) {
refferal = Number(mainAccount.telegramID);
}
}
}
}
return refferal;
}
async save(){
async save() {
await this.json.save(true);
}
async updateUser(account:interfacesDB.AccountInterface){
const index=await this.json.getIndex("/accounts", account.phoneNumber,"phoneNumber")
logger.debug(`Index in database is ${index} of ${account.phoneNumber}`)
await this.json.push(`/accounts[${index}]`,account,true);
async updateUser(account: interfacesDB.AccountInterface) {
const index = await this.json.getIndex(
"/accounts",
account.phoneNumber,
"phoneNumber"
);
logger.debug(`Index in database is ${index} of ${account.phoneNumber}`);
await this.json.push(`/accounts[${index}]`, account, true);
}
async addUser(account: Omit<interfacesDB.AccountInterface,
'balance' | 'withdraws' | 'completedGroupsTasks' | 'canBeRefferal'
| 'browserFingerprint' | 'faucetMail'>,wallets_json: string): Promise<void>{
async addUser(
account: Omit<
interfacesDB.AccountInterface,
| "balance"
| "withdraws"
| "completedGroupsTasks"
| "canBeRefferal"
| "browserFingerprint"
| "faucetMail"
>,
wallets_json: string
): Promise<void> {
const fingerprintGenerator = new FingerprintGenerator();
const fingerprint=fingerprintGenerator.getFingerprint({
devices: ['desktop'],
browsers: ['chrome'],
const fingerprint = fingerprintGenerator.getFingerprint({
devices: ["desktop"],
browsers: ["chrome"],
}).fingerprint;
const faucet:interfacesDB.faucetMailInterface | undefined=await this.findWallet(wallets_json);
if (faucet === undefined){
logger.error('Add new faucet accounts');
throw new Error('Add new faucet accounts');
}else {
const canBeRefferal: boolean=Math.random() < 0.5;
const _account: interfacesDB.AccountInterface={
phoneNumber:account.phoneNumber,
telegramID:account.telegramID,
apiID:account.apiID,
apiHash:account.apiHash,
password:account.password,
faucetMail:faucet,
stringSession:account.stringSession,
balance:0.0,
withdraws:[],
completedGroupsTasks:[],
canBeRefferal:canBeRefferal,
refferal:account.refferal,
browserFingerprint:fingerprint
}
await this.json.push(`/accounts[]`,_account);
const faucet: interfacesDB.faucetMailInterface | undefined =
await this.findWallet(wallets_json);
if (faucet === undefined) {
logger.error("Add new faucet accounts");
throw new Error("Add new faucet accounts");
} else {
const canBeRefferal: boolean = Math.random() < 0.5;
const _account: interfacesDB.AccountInterface = {
phoneNumber: account.phoneNumber,
telegramID: account.telegramID,
apiID: account.apiID,
apiHash: account.apiHash,
password: account.password,
faucetMail: faucet,
stringSession: account.stringSession,
balance: 0.0,
withdraws: [],
completedGroupsTasks: [],
canBeRefferal: canBeRefferal,
refferal: account.refferal,
browserFingerprint: fingerprint,
};
await this.json.push(`/accounts[]`, _account);
}
await this.save();
}
async getUsers(): Promise<interfacesDB.AccountInterface[]>{
async getUsers(): Promise<interfacesDB.AccountInterface[]> {
try {
return await this.json.getObject<interfacesDB.AccountInterface[]>('/accounts');
return await this.json.getObject<interfacesDB.AccountInterface[]>(
"/accounts"
);
} catch {
return [];
}
}
}
}
export class Settings implements interfacesSettings.settingsInterface {
public readonly default: interfacesSettings.settingsInterface={
logLevel: 'debug',
public readonly default: interfacesSettings.settingsInterface = {
logLevel: "debug",
pararels: 2,
mainCrypto: 'TRX',
mainCrypto: "TRX",
minimalToWithdraw: 0.0003,
maxRefferals: 3,
botMessages: {
verification: 'To continue using this bot,',
tasksSelector: 'Choose an option to start earning your TRX',
taskOver: 'Sorry, there are no new ads available.',
taskComplete: 'Success, ',
notInGroup: 'not entered the chat',
oldMessage: 'forwarded is old'
verification: "To continue using this bot,",
tasksSelector: "Choose an option to start earning your TRX",
taskOver: "Sorry, there are no new ads available.",
taskComplete: "Success, ",
notInGroup: "not entered the chat",
oldMessage: "forwarded is old",
},
botButtons: {
earn: '❇️ Earn cryptocurrency',
balance: '💰 Balance',
withdraw: '📤 Withdraw'
earn: "❇️ Earn cryptocurrency",
balance: "💰 Balance",
withdraw: "📤 Withdraw",
},
telegramLinks: {
botLink: '@hkearn_trx_bot',
groupsToJoin: ['@hkearn_transactions', '@hkearn_updates']
botLink: "@hkearn_trx_bot",
groupsToJoin: ["@hkearn_transactions", "@hkearn_updates"],
},
bypassMode: false,
sleepTime: {
afterDoing: [1*3600,2*3600],
betweenSessions: [35,70],
afterDoing: [1 * 3600, 2 * 3600],
betweenSessions: [35, 70],
},
shuffleAccounts: true
}
shuffleAccounts: true,
};
logLevel: "debug" | "info" | "error";
mainCrypto: "TRX";
minimalToWithdraw: number;
maxRefferals: number;
botMessages: { verification: string; tasksSelector: string; taskOver: string, taskComplete: string, notInGroup: string, oldMessage: string};
botButtons: { earn: string; balance: string; withdraw: string; };
telegramLinks: { botLink: string; groupsToJoin: string[]; };
bypassMode: boolean
pararels: number
botMessages: {
verification: string;
tasksSelector: string;
taskOver: string;
taskComplete: string;
notInGroup: string;
oldMessage: string;
};
botButtons: { earn: string; balance: string; withdraw: string };
telegramLinks: { botLink: string; groupsToJoin: string[] };
bypassMode: boolean;
pararels: number;
sleepTime: {
afterDoing: number[],
betweenSessions: number[],
}
shuffleAccounts: boolean
afterDoing: number[];
betweenSessions: number[];
};
shuffleAccounts: boolean;
private json: JsonDB;
constructor (){
this.json=new JsonDB(new Config('settings.json',false,true,'/'));
this.json.getObject<interfacesSettings.settingsInterface>('/').then((result) => {
if (Object.keys(result).length==0){
logger.warn('Setup config first...');
this.json.push('/',this.default,true)
.catch((err)=> logger.error(`${err} due setting defaults`))
.then(()=>{
this.json.save(true).then(()=>{
throw new Error("Config doesn't setup");
})
});
} else {
mainLoop:
for (const setting of Object.keys(this.default)){
if (result[setting]===undefined || typeof(result[setting])!=typeof(this.default[setting])){
this[setting]=this.default[setting];
logger.warn(`Setting '${setting}' corrupted or undefined. Check out it...`)
} else {
if (typeof(result[setting])=='object'){
for (const attr of Object.keys(this.default[setting])){
if (Object.keys(result[setting]).indexOf(attr)==-1){
this[setting] = this.default[setting];
logger.warn(`Setting '${setting}' corrupted. Check out it...`)
continue mainLoop;
constructor() {
this.json = new JsonDB(new Config("settings.json", false, true, "/"));
this.json
.getObject<interfacesSettings.settingsInterface>("/")
.then((result) => {
if (Object.keys(result).length == 0) {
logger.warn("Setup config first...");
this.json
.push("/", this.default, true)
.catch((err) =>
logger.error(`${err} due setting defaults`)
)
.then(() => {
this.json.save(true).then(() => {
throw new Error("Config doesn't setup");
});
});
} else {
mainLoop: for (const setting of Object.keys(this.default)) {
if (
result[setting] === undefined ||
typeof result[setting] !=
typeof this.default[setting]
) {
this[setting] = this.default[setting];
logger.warn(
`Setting '${setting}' corrupted or undefined. Check out it...`
);
} else {
if (typeof result[setting] == "object") {
for (const attr of Object.keys(
this.default[setting]
)) {
if (
Object.keys(result[setting]).indexOf(
attr
) == -1
) {
this[setting] = this.default[setting];
logger.warn(
`Setting '${setting}' corrupted. Check out it...`
);
continue mainLoop;
}
}
}
this[setting] = result[setting];
}
this[setting]=result[setting];
}
logger.level = this.logLevel;
}
logger.level=this.logLevel;
}
});
}
});
}
}
const database=new Database();
const settings=new Settings();
export {database,settings}
const database = new Database();
const settings = new Settings();
export { database, settings };

836
index.ts

File diff suppressed because it is too large Load Diff

View File

@ -1,38 +1,35 @@
import {Fingerprint} from "fingerprint-generator"
import { Fingerprint } from "fingerprint-generator";
export interface faucetMailInterface {
faucet: {
username: string,
password: string
}
username: string;
password: string;
};
mail: {
address: string,
password: string
}
address: string;
password: string;
};
}
export interface AccountCompletedGroupsTasksInterface {
timeToLeave: number,
groupID: string
timeToLeave: number;
groupID: string;
}
export interface AccountWithdrawInterface {
}
export interface AccountWithdrawInterface {}
export interface AccountInterface {
phoneNumber: string,
telegramID: number,
apiID: number,
apiHash: string,
password: string,
faucetMail: faucetMailInterface,
stringSession: string,
balance: number,
withdraws:AccountWithdrawInterface[],
completedGroupsTasks:AccountCompletedGroupsTasksInterface[],
canBeRefferal: boolean,
browserFingerprint:Fingerprint,
refferal:number | null
phoneNumber: string;
telegramID: number;
apiID: number;
apiHash: string;
password: string;
faucetMail: faucetMailInterface;
stringSession: string;
balance: number;
withdraws: AccountWithdrawInterface[];
completedGroupsTasks: AccountCompletedGroupsTasksInterface[];
canBeRefferal: boolean;
browserFingerprint: Fingerprint;
refferal: number | null;
}
export interface DatabaseInterface {
accounts: AccountInterface[]
accounts: AccountInterface[];
}

View File

@ -1,22 +1,20 @@
import * as telegram from 'telegram';
import {AccountInterface} from './databaseInterface'
import * as telegram from "telegram";
import { AccountInterface } from "./databaseInterface";
export interface prevTaskInterface {
task: telegram.Api.Message,
lastMessage:telegram.Api.Message
task: telegram.Api.Message;
lastMessage: telegram.Api.Message;
}
export interface portsInterface {
http: number,
socks: number,
control:number,
minerPort?:number
http: number;
socks: number;
control: number;
minerPort?: number;
}
export interface usedIPInterface{
worker: AccountInterface,
usedIps: string[],
current: string
}
export interface usedIPInterface {
worker: AccountInterface;
usedIps: string[];
current: string;
}

View File

@ -1,37 +1,33 @@
export interface settingsInterface {
logLevel: 'debug' | 'info' | 'error',
pararels: number,
mainCrypto: 'TRX',
minimalToWithdraw: number,
maxRefferals: number,
logLevel: "debug" | "info" | "error";
pararels: number;
mainCrypto: "TRX";
minimalToWithdraw: number;
maxRefferals: number;
// to find
botMessages: {
verification: string,
tasksSelector: string,
taskOver: string,
taskComplete: string,
notInGroup: string,
oldMessage: string
}
verification: string;
tasksSelector: string;
taskOver: string;
taskComplete: string;
notInGroup: string;
oldMessage: string;
};
// to send
botButtons:{
earn: string,
balance: string,
withdraw: string
},
botButtons: {
earn: string;
balance: string;
withdraw: string;
};
// to join
telegramLinks:{
botLink: string,
groupsToJoin: string[]
},
telegramLinks: {
botLink: string;
groupsToJoin: string[];
};
sleepTime: {
afterDoing: number[],
betweenSessions: number[]
},
shuffleAccounts: boolean
bypassMode: boolean
afterDoing: number[];
betweenSessions: number[];
};
shuffleAccounts: boolean;
bypassMode: boolean;
}

View File

@ -1,18 +1,19 @@
import winston = require("winston")
const logger=winston.createLogger({
level: 'debug',
import winston = require("winston");
const logger = winston.createLogger({
level: "debug",
format: winston.format.combine(
winston.format.colorize(),
winston.format.printf((info)=>{
return `${new Date().toLocaleTimeString()} | ${info.level} - ${info.message} `
winston.format.printf((info) => {
return `${new Date().toLocaleTimeString()} | ${info.level} - ${
info.message
} `;
})
),
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'errors.log', level: 'error' }),
new winston.transports.File({ filename: 'info.log' }),
new winston.transports.File({ filename: "errors.log", level: "error" }),
new winston.transports.File({ filename: "info.log" }),
],
});
export default logger;

View File

@ -19,7 +19,7 @@
},
"name": "hk_bot",
"version": "0.0.1",
"description": "test",
"description": "Script which allow earn some crypto via telegram",
"main": "/build/index.js",
"devDependencies": {
"@types/cli-progress": "^3.11.0",
@ -35,7 +35,7 @@
},
"repository": {
"type": "git",
"url": "https://notabug.org/minicx/hk_bot.git"
"url": "https://git.disroot.org/minicx/hk_bot.git"
},
"keywords": [
"telegram",
@ -44,5 +44,5 @@
"crypto"
],
"author": "minicx",
"license": "ISC"
"license": "MIT"
}

189
utils.ts
View File

@ -1,51 +1,83 @@
import Docker from "dockerode";
import logger from "./logger";
import {database as db,settings} from './database';
import { settings } from "./database";
// import Hero from "@ulixee/hero";
// import Miner from "@ulixee/miner";
import { sleep } from "telegram/Helpers";
import { AccountInterface } from "./interfaces/databaseInterface";
import * as telegram from 'telegram';
import * as telegram from "telegram";
import axios from "axios";
import cliProgress from "cli-progress"
export class CaptchaError extends Error{}
export class NoNewMessagesError extends Error{}
export class DockerIsBrockenError extends Error{}
import cliProgress from "cli-progress";
import { isNull, isUndefined } from "lodash";
export class CaptchaError extends Error {}
export class NoNewMessagesError extends Error {}
export class DockerIsBrockenError extends Error {}
export function randomAB(a: number, b: number) {
return Math.floor(Math.random() * (b - a + 1) + a);
}
export async function isBannedByClient(client: telegram.TelegramClient, username: string): Promise<boolean> {
const blockedUsers = (await client.invoke(new telegram.Api.contacts.GetBlocked({ limit: 2147483647 }))).users as telegram.Api.User[];
export async function isBannedByClient(
client: telegram.TelegramClient,
username: string
): Promise<boolean> {
const blockedUsers = (
await client.invoke(
new telegram.Api.contacts.GetBlocked({ limit: 2147483647 })
)
).users as telegram.Api.User[];
for (const blockedUser of blockedUsers) {
if (blockedUser.username !== undefined && blockedUser.username == username.replace('@', '')) {
if (
blockedUser.username !== undefined &&
blockedUser.username == username.replace("@", "")
) {
return true;
}
}
return false;
}
export async function getMessagesByEntity(client: telegram.TelegramClient, chatEntity: telegram.Api.Chat | telegram.Api.User | string, entity: telegram.Api.User | string, params = {}) {
let messages = new telegram.helpers.TotalList<telegram.Api.Message>;
export async function getMessagesByEntity(
client: telegram.TelegramClient,
chatEntity: telegram.Api.Chat | telegram.Api.User | string,
entity: telegram.Api.User | string,
params = {}
) {
const messages = new telegram.helpers.TotalList<telegram.Api.Message>();
if (entity instanceof telegram.Api.User) {
for (const message of await client.getMessages(chatEntity, params)) {
if ((message.sender as telegram.Api.User).username == entity.username) {
if (
(message.sender as telegram.Api.User).username ==
entity.username
) {
messages.push(message);
}
}
} else {
for (const message of await client.getMessages(chatEntity, params)) {
if ((message.sender as telegram.Api.User).username!.includes(entity.replace('@', ''))) {
messages.push(message);
if (
isNull((message.sender as telegram.Api.User).username) !=
true &&
isUndefined((message.sender as telegram.Api.User).username) !=
true
) {
if (
(message.sender as telegram.Api.User).username!.includes(
entity.replace("@", "")
)
) {
messages.push(message);
}
}
}
}
return messages;
}
export function arrayWithoutElementAtIndex(arr: AccountInterface[] | [], index: number) {
export function arrayWithoutElementAtIndex(
arr: AccountInterface[] | [],
index: number
) {
return arr.filter(function (value, arrIndex) {
return index !== arrIndex;
});
@ -54,13 +86,15 @@ export async function getIP(proxyPort: number): Promise<string | null> {
// https://github.com/ulixee/unblocked/blob/main/plugins/default-browser-emulator/lib/helpers/lookupPublicIp.ts
let data: string | PromiseLike<string | null> | null;
try {
data = (await axios.get('http://icanhazip.com/', {
proxy: {
host: '127.0.0.1',
port: proxyPort
},
timeout: 100000
})).data;
data = (
await axios.get("http://icanhazip.com/", {
proxy: {
host: "127.0.0.1",
port: proxyPort,
},
timeout: 100000,
})
).data;
} catch (err) {
logger.debug(err);
return null;
@ -70,92 +104,127 @@ export async function getIP(proxyPort: number): Promise<string | null> {
return null;
}
return await data;
}
export async function waitNewMessages(client: telegram.TelegramClient, worker: AccountInterface, chatEntity: telegram.Api.Chat | telegram.Api.User | string, idOfLastMessage: number, timeout: number = 20): Promise<void> {
export async function waitNewMessages(
client: telegram.TelegramClient,
worker: AccountInterface,
chatEntity: telegram.Api.Chat | telegram.Api.User | string,
idOfLastMessage: number,
timeout = 20
): Promise<void> {
const start_time = new Date();
while ((await getMessagesByEntity(client, chatEntity, chatEntity as telegram.Api.User | string, { minId: idOfLastMessage, limit: 2147483647 })).length == 0) {
if ((+(new Date()) - +start_time) / 1000 >= timeout) {
logger.error(`${worker.phoneNumber} | Bot didnt answer for ${timeout}s`);
throw new NoNewMessagesError('Is bot working?');
while (
(
await getMessagesByEntity(
client,
chatEntity,
chatEntity as telegram.Api.User | string,
{ minId: idOfLastMessage, limit: 2147483647 }
)
).length == 0
) {
if ((+new Date() - +start_time) / 1000 >= timeout) {
logger.error(
`${worker.phoneNumber} | Bot didnt answer for ${timeout}s`
);
throw new NoNewMessagesError("Is bot working?");
}
}
logger.debug(`${worker.phoneNumber} | Bot answered`);
}
export async function startNewTorDocker(proxyPort: number, socksPort: number, controlPort: number, mainProgressBar: cliProgress.MultiBar, timeout: number = 200): Promise<Docker.Container> {
export async function startNewTorDocker(
proxyPort: number,
socksPort: number,
controlPort: number,
mainProgressBar: cliProgress.MultiBar,
timeout = 200
): Promise<Docker.Container> {
timeout *= 2;
let docker = new Docker({ socketPath: '/var/run/docker.sock' });
const docker = new Docker({ socketPath: "/var/run/docker.sock" });
let isPulled = false;
mainLoop: for (const image of await docker.listImages()) {
const tags = image.RepoTags;
if (tags !== undefined)
for (const repoTag of tags) {
if (repoTag.search('dperson/torproxy:latest') != -1) {
if (repoTag.search("dperson/torproxy:latest") != -1) {
isPulled = true;
break mainLoop;
}
}
}
if (isPulled != true) {
await docker.pull('dperson/torproxy:latest');
await docker.pull("dperson/torproxy:latest");
}
// bugy shit
const options: Docker.ContainerCreateOptions = {
Image: 'dperson/torproxy',
Env: [
"PASSWORD=qwerty",
"LOCATION=US",
"TOR_NewCircuitPeriod=50",
],
Image: "dperson/torproxy",
Env: ["PASSWORD=qwerty", "LOCATION=US", "TOR_NewCircuitPeriod=50"],
ExposedPorts: {},
HostConfig: {
PortBindings: {
'8118/tcp': [{
HostPort: `${proxyPort}`
}],
'9050/tcp': [{
HostPort: `${socksPort}`
}],
'9051/tcp': [{
HostPort: `${controlPort}`
}]
}
"8118/tcp": [
{
HostPort: `${proxyPort}`,
},
],
"9050/tcp": [
{
HostPort: `${socksPort}`,
},
],
"9051/tcp": [
{
HostPort: `${controlPort}`,
},
],
},
},
Healthcheck: {
Interval: 2 * 1000000000,
Timeout: 50 * 1000000000,
StartPeriod: 50 * 1000000000,
// Test:['CMD_SHELL',`curl -sx localhost:8118 'https://check.torproject.org/' | grep -qm1 Congratulations`]
}
},
};
const container = await docker.createContainer(options);
await container.start();
const progressBar = mainProgressBar.create(timeout / 2, 0, { status: `Starting docker${(settings.logLevel == 'debug') ? ` ${proxyPort} ${socksPort} ${controlPort}` : ''}` });
while ((await container.inspect())!.State.Health!.Status != 'healthy') {
const progressBar = mainProgressBar.create(timeout / 2, 0, {
status: `Starting docker${
settings.logLevel == "debug"
? ` ${proxyPort} ${socksPort} ${controlPort}`
: ""
}`,
});
while ((await container.inspect())!.State.Health!.Status != "healthy") {
const state = (await container.inspect())!.State.Health!.Status;
if (progressBar.getProgress() >= timeout) {
await container.kill();
progressBar.update(timeout / 2, { status: 'Failed' });
progressBar.update(timeout / 2, { status: "Failed" });
progressBar.stop();
throw new DockerIsBrockenError(`Docker ${container.id} is broken`);
}
if (state == 'unhealthy') {
if (state == "unhealthy") {
await container.kill();
progressBar.update(timeout / 2, { status: 'Docker is unhealthy...' });
progressBar.update(timeout / 2, {
status: "Docker is unhealthy...",
});
progressBar.stop();
return await startNewTorDocker(proxyPort, socksPort, controlPort, mainProgressBar, timeout / 2);
return await startNewTorDocker(
proxyPort,
socksPort,
controlPort,
mainProgressBar,
timeout / 2
);
}
progressBar.increment();
await sleep(2000);
}
progressBar.update(0, { status: 'Started' });
progressBar.update(0, { status: "Started" });
progressBar.stop();
return container;
}