Skip to content

Commit

Permalink
Merge pull request #215 from MikiEremiki/develop
Browse files Browse the repository at this point in the history
refactor: оптимизация проверки запущенных команд
  • Loading branch information
MikiEremiki authored Nov 18, 2024
2 parents 0a247fd + f05c659 commit 446695e
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/middleware/check_run_conv_hl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,35 @@ async def check_run_conv_hl(
update: Update,
context: ContextTypes.DEFAULT_TYPE
):
query = update.callback_query
if query:
if 'Отменить' in query.data:
return
command = extract_command(update.effective_message.text)
if update.effective_message.text:
command = extract_command(update.effective_message.text)
else:
command = None
if command and context.user_data.get('conv_hl_run', False):
for k, v in COMMAND_DICT.items():
if command == v[0] and command != 'start':
keyboard = [add_btn_back_and_cancel(
postfix_for_cancel=context.user_data['postfix_for_cancel'] + '|',
add_back_btn=False)]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.effective_chat.send_message(
'У вас все еще запущен другой диалог.\n'
'Если вы хотите закончить с ним работу '
'нажмите кнопку Отмена и выполните новую команду',
reply_markup=reply_markup
)
raise ApplicationHandlerStop
commands = [
COMMAND_DICT['RESERVE'][0],
COMMAND_DICT['STUDIO'][0],
COMMAND_DICT['RESERVE_ADMIN'][0],
COMMAND_DICT['STUDIO_ADMIN'][0],
COMMAND_DICT['MIGRATION_ADMIN'][0],
COMMAND_DICT['BD_ORDER'][0],
COMMAND_DICT['BD_PAID'][0],
COMMAND_DICT['LIST'][0],
COMMAND_DICT['LIST_WAIT'][0],
COMMAND_DICT['AFISHA'][0],
COMMAND_DICT['SETTINGS'][0],
]
if command in commands:
keyboard = [add_btn_back_and_cancel(
postfix_for_cancel=context.user_data['postfix_for_cancel'] + '|',
add_back_btn=False)]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.effective_chat.send_message(
'У вас все еще запущен другой диалог.\n'
'Если вы хотите закончить с ним работу '
'нажмите кнопку Отмена и выполните новую команду',
reply_markup=reply_markup
)
raise ApplicationHandlerStop

application.add_handler(TypeHandler(Update, check_run_conv_hl), group=-40)

0 comments on commit 446695e

Please sign in to comment.