diff options
| -rw-r--r-- | bot.py | 10 | ||||
| -rw-r--r-- | keyboards.py | 3 | ||||
| -rw-r--r-- | states.py | 39 | ||||
| -rw-r--r-- | utils.py | 1 |
4 files changed, 51 insertions, 2 deletions
@@ -118,6 +118,11 @@ conversation_handler = ConversationHandler( ANSWER_RIGHT: [MessageHandler(Filters.text, States.main_menu, pass_user_data=True)], ANSWER_WRONG: [MessageHandler(Filters.text, States.show_task, pass_user_data=True)], + ASKING_QUESTION: [ + MessageHandler(Filters.regex(BackToMenuKeyboard.CANCEL), States.main_menu, pass_user_data=True), + MessageHandler(Filters.text, States.ask_question, pass_user_data=True), + ], + # ADMIN PANEL ADMIN_MENU: [ @@ -151,7 +156,10 @@ conversation_handler = ConversationHandler( ADMIN_ACCESS_DENIED: [MessageHandler(Filters.text, States.main_menu, pass_user_data=True)], }, - fallbacks=[CommandHandler('stop', stop)] + fallbacks=[ + CommandHandler('stop', stop), + MessageHandler(Filters.regex(MenuKeyboard.HELP), States.prompt_question, pass_user_data=True), + ] ) if __name__ == '__main__': diff --git a/keyboards.py b/keyboards.py index b2ed775..95294c1 100644 --- a/keyboards.py +++ b/keyboards.py @@ -13,6 +13,7 @@ class MenuKeyboard(Keyboard): TOP_10 = "Топ-10📊" RULES = "Правилаℹ️" ADMIN = "/admin" + HELP = "Задать вопрос🆘" @classmethod def get_keyboard(cls, telegram_id=None): @@ -23,11 +24,13 @@ class MenuKeyboard(Keyboard): [cls.ADMIN], [cls.CHOOSE_TASK], [cls.TOP_10, cls.RULES], + [cls.HELP], ] return [ [cls.CHOOSE_TASK], [cls.TOP_10, cls.RULES], + [cls.HELP], ] @@ -45,6 +45,44 @@ def calculate_attempts(attempts): class States: @staticmethod @save_state + def prompt_question(bot: Bot, update: Update, user_data: dict): + update.message.reply_text( + "Введите свой вопрос, админы вам ответят, как только появится возможность, " + "поэтому следите за сообщениями от бота.", + reply_markup=ReplyKeyboardMarkup(BackToMenuKeyboard.get_keyboard()) + ) + + return ASKING_QUESTION + + @staticmethod + @save_state + def ask_question(bot: Bot, update: Update, user_data: dict): + question = update.message.text + + code, profiles = backend_api.get_profiles() + if code != 200: + pass + + user_id = update.message.from_user.id + username = update.message.from_user.full_name + + for profile in profiles: + if profile["is_admin"]: + bot.send_message( + profile["tg_id"], f"*ВОПРОС ОТ ПОЛЬЗОВАТЕЛЯ {username} ({user_id})*:\n\n{question}", + parse_mode="Markdown" + ) + + update.message.reply_text( + "Ваш вопрос был отправлен на рассмотрение, ожидайте ответ.", + reply_markup=ReplyKeyboardMarkup(ContinueKeyboard.get_keyboard()) + ) + + return ANSWER_RIGHT + + + @staticmethod + @save_state def wait_for_username(bot: Bot, update: Update, user_data: dict): update.message.reply_text( "По правилам квиза ты не можешь участвовать, если у тебя не указано " @@ -85,7 +123,6 @@ class States: t = Decimal((ts - fp).total_seconds()) / Decimal(60) plr_score = calc_score(t, attempt["task"]["base_score"]) - print(plr_score) full_score += plr_score menu_text.append( @@ -3,6 +3,7 @@ MAIN_MENU, TOP_10, RULES, TASK_CHOOSING, TASK_SHOWN, ANSWERING, ANSWER_RIGHT, ANSWER_WRONG, + ASKING_QUESTION, ADMIN_MENU, ADMIN_TASK_CHOOSE_PUBLISH, ADMIN_TASK_CHOOSE_HIDE, ADMIN_WAIT_FOR_ANNOUNCEMENT, ADMIN_WAIT_FOR_MESSAGE, |