-
Notifications
You must be signed in to change notification settings - Fork 1
/
demotivator.py
72 lines (58 loc) · 2.68 KB
/
demotivator.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from telethon.events import NewMessage
from telethon.errors.rpcerrorlist import YouBlockedUserError
from asyncio.exceptions import TimeoutError, CancelledError
from .. import loader, utils
def register(cb):
cb(DemotivatorMod())
class DemotivatorMod(loader.Module):
"""Демотиватор от крабодяна"""
strings = {"name": "Демотиватор"}
async def client_ready(self, client, _):
self.client = client
async def demcmd(self, message):
""".dem <текст> <реплай на медиа>"""
reply = await message.get_reply_message()
if (
not reply
or not reply.media
or not any(
[
True
for _ in ("sticker", "photo", "video")
if getattr(reply, _, None) is not None
]
)
):
return await message.edit("<b>нужен реплай на фотку!</b>")
if reply.file.size / 1024 / 1024 > 1:
return await message.edit(
"<b>бот принимает видео до 1 мб (но можно скинуть бабла автору бота на сервер и будет до 5)</b>"
)
args = utils.get_args_raw(message) or reply.message
if not args:
return await message.edit("<b>укажи аргументы после команды...</b>")
if len(args) > 300:
return await message.edit(
"<b>бот принимает текст длинной до 200 символов</b>"
)
chat = "IvIy_bot"
await message.edit("<b>демотивирую...</b>")
async with self.client.conversation(chat, timeout=30) as conv:
try:
response = conv.wait_event(NewMessage(incoming=True, from_users=chat))
msg = await message.client.send_file(chat, reply.media)
await msg.reply(f"/demoti {args}")
response = await response
if not response.media:
response = conv.wait_event(
NewMessage(incoming=True, from_users=chat)
)
response = await response
except YouBlockedUserError:
return await message.edit(f"<b>Разблокируй @{chat}</b>")
except (TimeoutError, CancelledError):
return await message.edit(
"<b>бот не ответил => @krabodyan ебланище</b>"
)
await self.client.send_file(message.to_id, response.media, reply_to=reply)
await message.delete()