From e8dbbfe5c53f6666453ddfbf03f9a80faf171b65 Mon Sep 17 00:00:00 2001 From: Rykov7 Date: Sat, 28 Oct 2023 22:34:20 +0300 Subject: [PATCH] Add async --- app/commands/service.py | 16 ++++++++-------- app/stan.py | 13 +++---------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/app/commands/service.py b/app/commands/service.py index 64ac188..97f7231 100644 --- a/app/commands/service.py +++ b/app/commands/service.py @@ -12,29 +12,29 @@ from .get import me, my_ip @bot.message_handler(commands=["me"]) -def command_me(message): +async def command_me(message): """Send info about user and chat id [Service].""" - bot.send_message(message.chat.id, me(message)) + await bot.send_message(message.chat.id, me(message)) @bot.message_handler(func=is_admin, commands=["ip"]) -def get_ip(message): - bot.send_message(message.chat.id, my_ip()) +async def get_ip(message): + await bot.send_message(message.chat.id, my_ip()) @bot.message_handler(commands=["remind"]) -def remind_manually(message): +async def remind_manually(message): """Remind holidays manually.""" args = message.text.split() if len(args) > 1: try: today = dt.strptime(args[1], "%m-%d-%Y") except ValueError as ve: - bot.send_message(message.chat.id, f"Не удалось разобрать дату!\n{ve}") + await bot.send_message(message.chat.id, f"Не удалось разобрать дату!\n{ve}") else: - reminder.remind(message.chat.id, today) + await reminder.remind(message.chat.id, today) else: - bot.send_message( + await bot.send_message( message.chat.id, f"Формат даты: MM-DD-YYYY\n\n" f"Примеры:\n" diff --git a/app/stan.py b/app/stan.py index 8a1f3d1..b224859 100644 --- a/app/stan.py +++ b/app/stan.py @@ -59,22 +59,15 @@ async def remove_stan_quote(message: types.Message): if message.reply_to_message and message.reply_to_message.text: quote = html.escape(message.reply_to_message.text) - already_exist = session.query(Quote).filter_by(text=quote, - chat_id=message.chat.id).first() + already_exist = session.query(Quote).filter_by(text=quote, chat_id=message.chat.id).first() if already_exist: session.delete(already_exist) session.commit() - await bot.send_message( - message.chat.id, - f"✅ Удалил\n └ {quote}", - ) + await bot.send_message(message.chat.id, f"✅ Удалил\n └ {quote}",) await bot.delete_message(message.chat.id, message.id) else: - await bot.send_message( - message.chat.id, - f"⛔️ Нет такого\n └ {quote}", - ) + await bot.send_message(message.chat.id, f"⛔️ Нет такого\n └ {quote}",) @bot.message_handler(func=is_nongrata)