-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (27 loc) · 1.11 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from discord_webhook import DiscordWebhook
from telethon import TelegramClient, events
try:
import private_config as config
except ModuleNotFoundError:
import config
if config.use_proxy:
client = TelegramClient('session', config.api_id, config.api_hash,connection=config.proxy_type,proxy=config.proxy_settings)
else:
client = TelegramClient('session', config.api_id, config.api_hash)
@client.on(events.NewMessage)
async def my_event_handler(message):
chat = await message.get_chat()
if chat.title == config.channel_name or message.chat_id == config.channel_id:
webhook = DiscordWebhook(url=config.discord_webhook)
webhook.avatar_url = config.avatar_url
webhook.username = config.username
webhook.content = message.raw_text
if message.photo:
path = await client.download_media(message.media)
with open(path, "rb") as f:
webhook.add_file(file=f.read(), filename=str(message.photo.date)+".jpg")
webhook.execute()
os.remove(path)
client.start()
client.run_until_disconnected()