diff options
| author | Igor <50257429+igorechek06@users.noreply.github.com> | 2021-11-11 00:13:35 +0900 |
|---|---|---|
| committer | Igor <50257429+igorechek06@users.noreply.github.com> | 2021-11-11 00:13:35 +0900 |
| commit | f085526da14d7f84beee2c2b1150b1ebf829783e (patch) | |
| tree | 6ba678b087519571ad5186c9dd55ffb0836b3db6 | |
| parent | cb52a852985e9c327a6d5b64e942e620198b48b8 (diff) | |
| download | karpov_ai_bot-f085526da14d7f84beee2c2b1150b1ebf829783e.tar.gz karpov_ai_bot-f085526da14d7f84beee2c2b1150b1ebf829783e.zip | |
Bug fix (@arslee07 лох)
| -rw-r--r-- | handlers/__init__.py | 2 | ||||
| -rw-r--r-- | handlers/gif.py | 57 | ||||
| -rw-r--r-- | handlers/img.py | 52 | ||||
| -rw-r--r-- | test.py | 3 |
4 files changed, 56 insertions, 58 deletions
diff --git a/handlers/__init__.py b/handlers/__init__.py index 05e50a2..6ba46f4 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | from . import ananas_only | 1 | from . import ananas_only |
| 2 | from . import msg | 2 | from . import msg |
| 3 | from . import poll | 3 | from . import poll |
| 4 | from . import gif | 4 | from . import img |
| 5 | from . import gen | 5 | from . import gen |
| 6 | from . import all | 6 | from . import all |
diff --git a/handlers/gif.py b/handlers/gif.py deleted file mode 100644 index 5b3d5bc..0000000 --- a/handlers/gif.py +++ /dev/null | |||
| @@ -1,57 +0,0 @@ | |||
| 1 | from os import system as run | ||
| 2 | |||
| 3 | from aiogram import types as t | ||
| 4 | from aiogram.dispatcher import filters | ||
| 5 | |||
| 6 | from shared.instances import dp | ||
| 7 | |||
| 8 | |||
| 9 | @dp.message_handler( | ||
| 10 | filters.Command("gif", ignore_caption=False), | ||
| 11 | content_types=[t.ContentType.PHOTO, t.ContentType.DOCUMENT], | ||
| 12 | ) | ||
| 13 | async def высрать_гифку_по_фото(msg: t.Message): | ||
| 14 | from handlers.gen import получить_говно | ||
| 15 | |||
| 16 | if await скачать_и_обработать_файл(msg): | ||
| 17 | with open("tmp/gif.mp4", "rb") as file: | ||
| 18 | await msg.reply_animation(file, caption=получить_говно()) | ||
| 19 | |||
| 20 | |||
| 21 | @dp.message_handler( | ||
| 22 | commands=["gif"], | ||
| 23 | content_types=[t.ContentType.TEXT], | ||
| 24 | ) | ||
| 25 | async def высрать_гифку_по_ответу(msg: t.Message): | ||
| 26 | from handlers.gen import получить_говно | ||
| 27 | |||
| 28 | if await скачать_и_обработать_файл(msg): | ||
| 29 | with open("tmp/gif.mp4", "rb") as file: | ||
| 30 | await msg.reply_animation(file, caption=получить_говно()) | ||
| 31 | |||
| 32 | |||
| 33 | async def скачать_и_обработать_файл(msg: t.Message): | ||
| 34 | tmp = "tmp/" | ||
| 35 | inp = tmp + "gif.jpg" | ||
| 36 | out = tmp + "gif.mp4" | ||
| 37 | |||
| 38 | try: | ||
| 39 | if msg.text: | ||
| 40 | photo = msg.reply_to_message.photo | ||
| 41 | document = msg.reply_to_message.document | ||
| 42 | else: | ||
| 43 | photo = msg.photo | ||
| 44 | document = msg.document | ||
| 45 | |||
| 46 | if photo: | ||
| 47 | await photo[-1].download(destination_file=inp) | ||
| 48 | elif document: | ||
| 49 | await document.download(destination_file=inp) | ||
| 50 | else: | ||
| 51 | raise RuntimeError() | ||
| 52 | except Exception: | ||
| 53 | await msg.reply("Чел, ответь на фото или пришли мне его") | ||
| 54 | return False | ||
| 55 | |||
| 56 | run(f"ffmpeg -loglevel quiet -y -i {inp} {out}") | ||
| 57 | return True | ||
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 @@ | |||
| 1 | from os import system as run | ||
| 2 | |||
| 3 | from aiogram import types as t | ||
| 4 | from aiogram.dispatcher import filters | ||
| 5 | |||
| 6 | from handlers.gen import получить_говно | ||
| 7 | from shared.instances import dp, bot | ||
| 8 | |||
| 9 | |||
| 10 | async 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 | |||
| 31 | def удалить(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 | ) | ||
| 39 | async 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) | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | n = int(input("-> ")) | ||
| 2 | |||
| 3 | print(n % 2 == 0) | ||
