0
async def convert(sessionId, isShadow=None, userId=None):
    if userId:
        try:
            if conn.cursor().execute(f'SELECT * FROM users WHERE userId == {userId}').fetchone()[0]:
                path = f'users\\{userId}\\sessions\\'
            else:
                bot.send_message(userId, 'Ошибка, ваших сессий не найдено.')
                return 'SESSIONS_NOT_FOUND not exception'
        except Exception as e:
            try:
                bot.send_message(userId, 'Ошибка, ваших сессий не найдено.')
                return f'SESSIONS_NOT_FOUND exception: {e}'
            except telebot.apihelper.ApiTelegramException as e:
                if 'chat not found' in e: return 'INVALID_ID'
                else: return 'UNEXCEPTED_ERROR'
    else:
        if isShadow: path = f'shadowSessions\\'
        else: path = f'sessions\\'

    sessionData = json.load(open(f'{path}\\{sessionId.replace(".session",".json")}'))
    app_id   = sessionData["app_id"]
    app_hash = sessionData["app_hash"]
    try:
        session = await SessionManager.from_telethon_file(Path(f'{path}{sessionId}'))
        res = session.to_pyrogram_string()
        return res
    except Exception as e:
        print(e)
        return False
async def initAcc(sessionId, userId=None, isShadow=None):
    try:
        path = f'shadowSessions' if isShadow else f'users/{userId}/sessions' if userId else 'sessions'
        
        if userId:
            if not conn.cursor().execute(f'SELECT * FROM users WHERE userId == {userId}').fetchone()
                bot.send_message(userId, 'Ошибка, ваших сессий не найдено.')
                return 'SESSIONS_NOT_FOUND not exception'
        else:
            if isShadow:
                path = f'shadowSessions'
            else:
                path = f'sessions'
        
        sessionData = json.load(open(f'{path}/{sessionId.replace(".session",".json")}'))
        app_id = sessionData["app_id"]
        app_hash = sessionData["app_hash"]
        proxy = sessionData["proxy"]
        user = proxy[4] if proxy[4] != 'None' else None
        password = proxy[5] if proxy[5] != 'None' else None
        host = proxy[1]
        port = proxy[2]
        
        proxy = {
            "scheme": 'socks5',
            "hostname": host,
            "port": int(port),
            "username": user,
            "password": password}
        
        client = Client(f'{path}/{sessionId.replace(".session","")}', session_string=await convert(sessionId), api_id=app_id, api_hash=app_hash, proxy=proxy, lang_code='ru')
        return client
    
    except Exception as e:
        print(e)
        return False
  1. Telethot to pyrogram session convertation code
  2. Client object initialization

All proxies work.

i can't make it work normally like for week.

ChatGPT says all normal and there is no any syntax errors.

Before it worked good, old accs got banned by other causes.

Idk, seems like all good, but accs gots banned after .start() +- 1 minute later

  • Telegram may automatically ban accounts if they detect that they might be used for spam, scam. So what happens to you it's normal. If you think the bans are wrong you can try to contact Telegram :) – Marcel Alexandru Jun 28 '23 at 10:05

0 Answers0