Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't forward, re-send , how can i modify the code #6

Open
wangxiaoer5 opened this issue Apr 13, 2022 · 0 comments
Open

Don't forward, re-send , how can i modify the code #6

wangxiaoer5 opened this issue Apr 13, 2022 · 0 comments

Comments

@wangxiaoer5
Copy link

#!/usr/bin/env python
import asyncio
import logging

from telethon import TelegramClient, events

import config

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(name)

client = TelegramClient(config.SESSION_NAME, config.API_ID, config.API_HASH)
client.start()

RELAY_MAP = {}

async def setup():
user = await client.get_me()
logger.info('Started serving as {}'.format(user.first_name))
await client.get_dialogs()

for x in config.RELAY_MAP.split(';'):
    if not x:
        return

    key, values = x.split(':', 1)
    values = values.split(',')
    RELAY_MAP[int(key)] = [int(x) for x in values]

@client.on(events.NewMessage)
async def my_event_handler(event):
for chat_id, relays in RELAY_MAP.items():
if event.chat and event.chat.id == chat_id:
for relay in relays:
logger.info('Sending message from {} to {}'.format(event.chat.id, relay))
if config.FORWARD:
await client.forward_messages(relay, event.message)
else:
await client.send_message(relay, event.message)
break
else:
for relay in RELAY_MAP.get('default', []):
logger.info('Sending message from {} to {}'.format(event.chat.id, relay))
if config.FORWARD:
await client.forward_messages(relay, event.message)
else:
await client.send_message(relay, event.message)

loop = asyncio.get_event_loop()
loop.run_until_complete(setup())
client.run_until_disconnected()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant