From da06b5ad2378372f9b4f9e8eb22b86ea393b551e Mon Sep 17 00:00:00 2001 From: hopelessjames Date: Mon, 19 Jun 2023 19:24:40 +1000 Subject: [PATCH] minor fixes and PEP8'ification --- handlers/pipisa.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/handlers/pipisa.py b/handlers/pipisa.py index b915d61..5f50837 100644 --- a/handlers/pipisa.py +++ b/handlers/pipisa.py @@ -25,6 +25,13 @@ def top_dick_message(delimiter, top_list): f'🌶 {delimiter.join(map(str, top_list[7]))}\n' f'👌 {delimiter.join(map(str, top_list[8]))}\n' f'💩 {delimiter.join(map(str, top_list[9]))}\n' + return message + + +@dp.message_handler(commands=["maintainance"]) +async def stop_for_maintenance(message: types.Message): # остановить бота + if message.from_user.id == 226765676: + close_all_sessions() # TODO Вспомнить, как это, блять, делается. @dp.message_handler(commands=["dick"]) @@ -32,10 +39,10 @@ async def up_dick(message: types.Message): # рандомайзер numb = randint(-6, 10) global size_change, dick_plus, dick_minus - dick_plus = ('вырос', 'подрос', 'привстал') + dick_plus = ('вырос', 'подрос', 'привстал') dick_minus = ('уменьшился', 'откусила злая гадюка', 'продали евреи, он стал дешевле') if numb > 0: - size_change = random.choice(dick_plus) + '🚀' + size_change = random.choice(dick_plus) + '🚀' # if numb = 0 size_change = random.choice(const) TODO else: size_change = random.choice(dick_minus) + '✂' @@ -134,7 +141,8 @@ async def send_topchat(message: types.Message): session.close() else: session.close() - top = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).filter(user.chat_id == chats).limit(10).all() + users = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()) + top = users.filter(user.chat_id == chats).limit(10).all() # проверка на длину списка, если меньше limit, то: @@ -149,14 +157,13 @@ async def send_topchat(message: types.Message): else: await bot.send_message(message.chat.id, top_dick_message(delimiter, top)) - except: + except Exception as e: session.rollback() - print('ошибка в /topdick') + print('ошибка в /topdick. Трейсбэк:\n' + '\n'.join(traceback.format_tb(e.__traceback__))) finally: session.close_all() - @dp.message_handler(commands=["globaldick"]) async def send_global_top(message: types.Message): try: @@ -165,9 +172,9 @@ async def send_global_top(message: types.Message): delimiter = ': ' await bot.send_message(message.chat.id, top_dick_message(delimiter, top_chat)) - except: + except Exception as e: session.rollback() - print('ошибка в /globaldick') + print('ошибка в /globaldick, трейсбэк:\n' + '\n'.join(traceback.format_tb(e.__traceback__))) finally: session.close_all() @@ -176,4 +183,3 @@ async def send_global_top(message: types.Message): # dp.register_message_handler(up_dick) # dp.register_message_handler(send_topchat) # dp.register_message_handler(send_global_top) -