aboutsummaryrefslogtreecommitdiff
path: root/handlers/img.py
diff options
context:
space:
mode:
Diffstat (limited to 'handlers/img.py')
-rw-r--r--handlers/img.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/handlers/img.py b/handlers/img.py
new file mode 100644
index 0000000..61606f3
--- /dev/null
+++ b/handlers/img.py
@@ -0,0 +1,52 @@
1from os import system as run
2
3from aiogram import types as t
4from aiogram.dispatcher import filters
5
6from handlers.gen import получить_говно
7from shared.instances import dp, bot
8
9
10async def скачать(name: str) -> str:
11 msg = t.Message.get_current()
12 if msg.content_type == t.ContentType.TEXT:
13 if msg.reply_to_message is None:
14 await msg.answer("Эээм… а где ответ ?")
15 return
16 msg = msg.reply_to_message
17
18 if msg.content_type == t.ContentType.PHOTO:
19 file_id = msg.photo[-1].file_id
20 elif msg.content_type == t.ContentType.DOCUMENT:
21 file_id = msg.document.file_id
22 else:
23 await msg.answer("Эээм… а где фото ?")
24 return
25
26 name = f"{name}.{msg.from_user.id}.{msg.chat.id}"
27 await bot.download_file_by_id(file_id, destination=f"tmp/{name}.jpg")
28 return name
29
30
31def удалить(name: str):
32 run(f"rm -rf tmp/*{name}*")
33
34
35@dp.message_handler(
36 filters.Command("gif", ignore_caption=False),
37 content_types=[t.ContentType.PHOTO, t.ContentType.DOCUMENT, t.ContentType.TEXT],
38)
39async def высрать_гифку_по_фото(msg: t.Message):
40 name = await скачать("gif")
41 run(
42 " ".join(
43 [
44 "ffmpeg -loglevel quiet -y",
45 f"-i tmp/{name}.jpg",
46 '-vf scale="ceil(iw/2)*2:ceil(ih/2)*2"',
47 f"tmp/{name}.mp4",
48 ]
49 )
50 )
51 await msg.answer_animation(open(f"tmp/{name}.mp4", "rb"), caption=получить_говно())
52 удалить(name)