Skip to content

Instantly share code, notes, and snippets.

@sofa-dm
Forked from aliforever/forwarder.py
Created March 12, 2024 17:55
Show Gist options
  • Save sofa-dm/2f5fed4c7c1b9c01f5f3074b75e186f3 to your computer and use it in GitHub Desktop.
Save sofa-dm/2f5fed4c7c1b9c01f5f3074b75e186f3 to your computer and use it in GitHub Desktop.

Revisions

  1. @aliforever aliforever created this gist Aug 17, 2019.
    33 changes: 33 additions & 0 deletions forwarder.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # After running the script in logging in to your account, send "forward_unseen:mister_x:10" to your saved messages,
    # the bot will then forward 10 last messages of the first user with name mister_x to your saved messages.
    # This way you can check what people have sent you without them knowing you did.

    from telethon import TelegramClient, events, sync
    from telethon.tl.types import PeerUser

    api_id = # Your Telegram API id here
    api_hash = # Your Telegram API hash here

    client = TelegramClient("Session_Name", api_id, api_hash)
    client.start()


    @client.on(events.NewMessage)
    async def my_event_handler(event):
    if "forward_unseen:" in event.raw_text:
    command = event.raw_text.split(":")
    name = command[1]
    count = command[2]
    for dialog in await client.iter_dialogs():
    if dialog.title == name:
    user = client.get_entity(PeerUser(dialog.id))
    i = 1
    for chat in client.iter_messages(user):
    await client.forward_messages(client.get_me(), chat, user)
    if i >= count:
    break
    i += 1
    break


    client.run_until_disconnected()