blob: 19c3b4f6ef5fcc9767c6f97dd8c06cb6f6306bd0 (
plain)
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
|
from os import system as run
from aiogram import types as t
from aiogram.dispatcher import filters
from handlers.gen import получить_говно
from shared.instances import dp, bot
async def скачать(name: str) -> str:
msg = t.Message.get_current()
if msg.content_type == t.ContentType.TEXT:
if msg.reply_to_message is None:
await msg.answer("Эээм… а где ответ ?")
return
msg = msg.reply_to_message
if msg.content_type == t.ContentType.PHOTO:
file_id = msg.photo[-1].file_id
elif msg.content_type == t.ContentType.DOCUMENT:
file_id = msg.document.file_id
else:
await msg.answer("Эээм… а где фото ?")
return
name = f"{name}.{msg.from_user.id}.{msg.chat.id}"
await bot.download_file_by_id(file_id, destination=f"tmp/{name}.jpg")
return name
def удалить(name: str):
run(f"rm -rf tmp/*{name}*")
@dp.message_handler(
filters.Command("gif", ignore_caption=False),
content_types=[t.ContentType.PHOTO, t.ContentType.DOCUMENT, t.ContentType.TEXT],
)
async def высрать_гифку_по_фото(msg: t.Message):
name = await скачать("gif")
run(
" ".join(
[
"ffmpeg -loglevel quiet -y",
f"-i tmp/{name}.jpg",
'-vf scale="ceil(iw/2)*2:ceil(ih/2)*2"',
f"tmp/{name}.mp4",
]
)
)
await msg.answer_animation(open(f"tmp/{name}.mp4", "rb"), caption=получить_говно())
удалить(name)
|