-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
26 lines (20 loc) · 810 Bytes
/
bot.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
#!/usr/bin/env python3
import os
import random
import logging
from telethon import TelegramClient, events
from telethon.tl.types import InputFile
max_stickers = len(os.listdir("images"))
client = TelegramClient("wypierdalajbot", os.getenv("APP_ID"), os.getenv("APP_HASH"))
client.start(bot_token=os.getenv("BOT_TOKEN"))
@events.register(events.NewMessage(incoming=True, forwards=False, pattern=r"^.*(?i)wypierdalaj.*$"))
async def handler(event):
r = random.Random().randint(1, max_stickers)
await client.send_file(
entity=event.chat_id,
file=os.path.join("images", str(r).zfill(4) + ".webp"),
reply_to=event.reply_to_msg_id if event.is_reply else event.message.id
)
if __name__ == "__main__":
client.add_event_handler(handler)
client.run_until_disconnected()