Загрузка...

Bot Traffer

Thread in Python created by zxcFlezyi Jan 22, 2025. (bumped Mar 14, 2025) 225 views

  1. zxcFlezyi
    zxcFlezyi Topic starter Jan 22, 2025 Banned 65 Oct 26, 2024
    Здравствуйте дорогие трафферы) этот код пишет опредленное сообщение под новыми постами :finger_up:


    Code
    from telethon import TelegramClient, events, sync
    from telethon.sessions import SQLiteSession
    import asyncio
    import time
    import os
    from telethon.tl.functions.account import UpdateStatusRequest
    from telethon.errors import SessionPasswordNeededError

    api_id =
    api_hash = ""
    phone_number = ""
    message_to_send = '***!!!'
    max_login_attempts = 3
    session_file = 'user_bot_session.db'
    session_path = os.path.join(os.getcwd(), session_file)
    system_version_str = '4.16.30-vxCUSTOM'

    client = TelegramClient(SQLiteSession(session_path), api_id, api_hash, system_version=system_version_str)


    async def main():
    login_attempts = 0
    while login_attempts < max_login_attempts:
    try:
    await client.connect()
    if not await client.is_user_authorized():
    try:
    await client.start(phone=phone_number)
    except SessionPasswordNeededError:
    password = input("Введите пароль двухэтапной аутентификации: ")
    await client.start(phone=phone_number, password=password)

    await client(UpdateStatusRequest(offline=False))
    print("Ботек включен, жду новых постов")
    break
    except Exception as e:
    print(f"Ошибка при входе: {e}. Попытка {login_attempts + 1} из {max_login_attempts}")
    login_attempts += 1
    await asyncio.sleep(5)

    if login_attempts == max_login_attempts:
    print("Не удалось войти в аккаунт после нескольких попыток.")
    return

    @client.on(events.NewMessage)
    async def handle_new_message(event):
    if event.is_channel and not event.is_private and event.message.from_id is None:
    try:
    chat = await event.get_chat()
    if not chat.left:
    await event.reply(message_to_send)
    print(f"Отправлено сообщение в канал: {event.chat_id} {event.message.id}")
    else:
    print(f"Бот заблокирован в канале {event.chat_id}")
    except Exception as e:
    print(f"Ошибка при отправке сообщения в канал {event.chat_id}: {e}")

    try:
    await client.run_until_disconnected()
    except Exception as e:
    print(f"Произошла ошибка во время работы бота: {e}")
    finally:
    await client.disconnect()

    if __name__ == "__main__":
    asyncio.run(main())
     
    1. okryjnost
    2. zxcFlezyi Topic starter
Top
Loading...