From c88bf46e873913533bc913ee5fb7496e18d6ad17 Mon Sep 17 00:00:00 2001 From: Rykov7 Date: Fri, 10 Feb 2023 23:37:01 +0300 Subject: [PATCH] refactor stan --- app/bot.py | 14 +------------- app/stan.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/bot.py b/app/bot.py index b2c0e01..edca585 100644 --- a/app/bot.py +++ b/app/bot.py @@ -1,9 +1,6 @@ import shelve - from flask import request, abort - import threading -from time import sleep from . import stan from . import report @@ -226,15 +223,6 @@ def default_query(inline_query): """ -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') - sleep(after_sec) # Typing time - bot.send_message(message.chat.id, quote) - - @bot.message_handler(content_types=['text', 'sticker', 'photo', 'animation', 'video', 'audio', 'document'], chat_types=['supergroup', 'group']) def handle_msg(message: types.Message): @@ -251,7 +239,7 @@ def handle_msg(message: types.Message): quote = stan.speak(50) if quote: - threading.Thread(target=send_quote, args=(len(quote) * 0.13, message, quote)).start() + threading.Thread(target=stan.send_quote, args=(len(quote) * 0.13, message, quote)).start() """ diff --git a/app/stan.py b/app/stan.py index 7891e57..0dbbd31 100644 --- a/app/stan.py +++ b/app/stan.py @@ -1,5 +1,6 @@ """ Stan's commands and reactions. """ import random +from time import sleep from .config import bot, types from .filters import is_white, is_nongrata @@ -10,6 +11,15 @@ def speak(chance_of): return random.choice([i.rstrip() for i in open('Stan.txt', 'r', encoding='utf8') if i]) +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') + sleep(after_sec) # Typing time + bot.send_message(message.chat.id, quote) + + @bot.message_handler(func=is_white, commands=['add']) def add_stan_quote(message): if message.reply_to_message and message.reply_to_message.text: