fixes of issue #8,#7,#1

This commit is contained in:
minicx 2022-12-14 15:20:31 +03:00
parent 6a518db77b
commit 2e0a82058f
2 changed files with 29 additions and 5 deletions

View File

@ -315,7 +315,21 @@ const farm: () => Promise<void> = async () => {
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 }));
try {
await client.invoke(new telegram.Api.channels.JoinChannel({ channel: chat }));
} catch (err){
if (err instanceof telegram.errors.RPCError){
switch (err.errorMessage) {
case 'CHANNELS_TOO_MUCH':
logger.error(`Too much groups | ${worker.phoneNumber}`);
continue workersLoop
default:
logger.error(`Some error due joining HK groups | ${worker.phoneNumber}\n${err.message}\n${err.stack}`);
continue workersLoop
}
}
}
} else {
logger.error(`Unknown error due GetParticipant | ${worker.phoneNumber}`)
throw err;
@ -483,13 +497,19 @@ const farm: () => Promise<void> = async () => {
// menu
(async () => {
while (true) {
let accounts: AccountInterface[]=[];
try {
accounts=(await db.getUsers());
} catch (err){
continue
}
const answer = await prompt({
type: 'select',
name: 'menu',
message: 'Choose action',
choices: [
((await db.getUsers()).length > 0) ? { title: 'Start', description: 'Starting farm', value: 'start' } : { title: 'Start', description: 'Add accounts first...', value: 'start', disabled: true },
(accounts.length > 0) ? { title: 'Start', description: 'Starting farm', value: 'start' } : { title: 'Start', description: 'Add accounts first...', value: 'start', disabled: true },
{ title: 'Add accounts', description: 'Add accounts to database', value: 'addAccounts' },
{ title: 'Check balances', value: 'checkBalances', disabled: true },
{ title: 'Withdraw', value: 'withdraw', disabled: true },

View File

@ -9,6 +9,7 @@ import { AccountInterface } from "./interfaces/databaseInterface";
import * as telegram from 'telegram';
import axios from "axios";
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{}
@ -37,9 +38,12 @@ export async function getMessagesByEntity(client: telegram.TelegramClient, chatE
}
} 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);
}
}
}
}