Merge pull request 'feat: add more random captions for /uwu' (#17) from Furrex/bot_tg:main into main
Reviewed-on: #17
This commit is contained in:
commit
29cd511186
1 changed files with 19 additions and 3 deletions
22
games/uwu.py
22
games/uwu.py
|
|
@ -2,9 +2,15 @@ import aiohttp
|
||||||
from aiogram import types
|
from aiogram import types
|
||||||
import config
|
import config
|
||||||
import logging
|
import logging
|
||||||
|
import random
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CAPTIONS = [
|
||||||
|
"Ня :3",
|
||||||
|
"uwu"
|
||||||
|
]
|
||||||
|
|
||||||
async def handle_uwu_cmd(message: types.Message):
|
async def handle_uwu_cmd(message: types.Message):
|
||||||
args = message.text.split(maxsplit=1)
|
args = message.text.split(maxsplit=1)
|
||||||
|
|
||||||
|
|
@ -16,12 +22,12 @@ async def handle_uwu_cmd(message: types.Message):
|
||||||
"• <b>score</b>: <code>score:>500</code> (искать популярные посты с рейтингом больше 500)\n"
|
"• <b>score</b>: <code>score:>500</code> (искать популярные посты с рейтингом больше 500)\n"
|
||||||
"• Исключить тег: поставьте минус, например <code>-fox</code>\n\n"
|
"• Исключить тег: поставьте минус, например <code>-fox</code>\n\n"
|
||||||
"<i>Пример:</i> <code>/uwu wolf -rating:explicit score:>100</code>\n"
|
"<i>Пример:</i> <code>/uwu wolf -rating:explicit score:>100</code>\n"
|
||||||
"<i>По умолчанию:</i> <code>rating:safe score:>500</code>"
|
"<i>По умолчанию:</i> <code>rating:safe score:>500 -animated</code>"
|
||||||
)
|
)
|
||||||
await message.reply(help_msg, parse_mode="HTML")
|
await message.reply(help_msg, parse_mode="HTML")
|
||||||
return
|
return
|
||||||
|
|
||||||
tags = "rating:safe score:>500"
|
tags = "rating:safe score:>500 -animated"
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
tags = args[1].strip()
|
tags = args[1].strip()
|
||||||
|
|
||||||
|
|
@ -57,11 +63,21 @@ async def handle_uwu_cmd(message: types.Message):
|
||||||
|
|
||||||
post = posts[0]
|
post = posts[0]
|
||||||
file_url = post.get("file", {}).get("url")
|
file_url = post.get("file", {}).get("url")
|
||||||
|
ext = post.get("file", {}).get("ext", "png")
|
||||||
if not file_url:
|
if not file_url:
|
||||||
await message.reply("У найденного поста нет прямого URL изображения :(")
|
await message.reply("У найденного поста нет прямого URL изображения :(")
|
||||||
return
|
return
|
||||||
|
|
||||||
await message.answer_photo(photo=types.URLInputFile(file_url), caption="Ня :3")
|
input_file = types.URLInputFile(file_url)
|
||||||
|
caption = random.choice(CAPTIONS)
|
||||||
|
if ext in ("png", "jpg", "jpeg", "webp"):
|
||||||
|
await message.answer_photo(photo=input_file, caption=caption)
|
||||||
|
elif ext == "gif":
|
||||||
|
await message.answer_animation(animation=input_file, caption=caption)
|
||||||
|
elif ext in ("webm", "mp4"):
|
||||||
|
await message.answer_video(video=input_file, caption=caption)
|
||||||
|
else:
|
||||||
|
await message.answer_document(document=input_file, caption=caption)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Error in uwu command")
|
logger.exception("Error in uwu command")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue