Switch to async!

This commit is contained in:
Rykov7
2023-10-28 18:47:34 +03:00
parent 65e04a36e0
commit 5d179b0de2
7 changed files with 136 additions and 233 deletions
+13 -13
View File
@@ -15,15 +15,15 @@ def speak(chance_of, group_id):
return random.choice([i[0] for i in session.query(Quote.text).filter(Quote.chat_id == group_id).all()])
def send_quote(after_sec, message, quote):
async def send_quote(after_sec, message, quote):
"""Pretend Reading, pretend Typing, send."""
if message.text:
sleep(
len(message.text) * 0.13 / 4
) # Reading time is quarter of the same text writing time
bot.send_chat_action(message.chat.id, action="typing")
await bot.send_chat_action(message.chat.id, action="typing")
sleep(after_sec) # Typing time
bot.send_message(message.chat.id, html.escape(quote))
await bot.send_message(message.chat.id, html.escape(quote))
def act(message: types.Message):
@@ -33,29 +33,29 @@ def act(message: types.Message):
@bot.message_handler(func=is_white, commands=["add"])
def add_stan_quote(message: types.Message):
async def add_stan_quote(message: types.Message):
if message.reply_to_message and message.reply_to_message.text:
quote = html.escape(message.reply_to_message.text)
if quote not in [i[0] for i in session.query(Quote.text).filter(
Quote.chat_id == message.chat.id).all()]:
session.add(Quote(chat_id=message.chat.id, text=quote.replace("\n", " ")))
session.commit()
bot.send_message(
await bot.send_message(
message.chat.id,
"✅ <b>Добавил</b>\n └ <i>"
+ quote.replace("\n", " ")
+ "</i>",
)
bot.delete_message(message.chat.id, message.id)
await bot.delete_message(message.chat.id, message.id)
else:
bot.send_message(
await bot.send_message(
message.chat.id,
f"⛔️ <b>Не добавил</b>, есть токое\n └ <i>{quote}</i>",
)
@bot.message_handler(func=is_white, commands=["remove"])
def remove_stan_quote(message: types.Message):
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)
@@ -65,19 +65,19 @@ def remove_stan_quote(message: types.Message):
session.delete(already_exist)
session.commit()
bot.send_message(
await bot.send_message(
message.chat.id,
f"✅ <b>Удалил</b>\n └ <i>{quote}</i>",
)
bot.delete_message(message.chat.id, message.id)
await bot.delete_message(message.chat.id, message.id)
else:
bot.send_message(
await bot.send_message(
message.chat.id,
f"⛔️ <b>Нет такого</b>\n └ <i>{quote}</i>",
)
@bot.message_handler(func=is_nongrata)
def tease_nongrata(message: types.Message):
async def tease_nongrata(message: types.Message):
"""Reply to non grata mentions."""
bot.reply_to(message, f"у нас тут таких не любят")
await bot.reply_to(message, f"у нас тут таких не любят")