summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2020-02-23 16:15:55 +0400
committerAndrew <saintruler@gmail.com>2020-02-23 16:15:55 +0400
commit7512932056b1edf82c3c711a9297445ac8c0cc52 (patch)
treeba8d686b8cd63964ecbf67e6f340ee2134ef5b03
parentfe016a980f9ac422c3ee940b4676184532a30b26 (diff)
Added contact support views.
-rw-r--r--bot.py10
-rw-r--r--keyboards.py3
-rw-r--r--states.py39
-rw-r--r--utils.py1
4 files changed, 51 insertions, 2 deletions
diff --git a/bot.py b/bot.py
index aee7d82..9609bb9 100644
--- a/bot.py
+++ b/bot.py
@@ -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],
]
diff --git a/states.py b/states.py
index eaadd4a..bb1455d 100644
--- a/states.py
+++ b/states.py
@@ -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(
diff --git a/utils.py b/utils.py
index 473cf9d..933f0e8 100644
--- a/utils.py
+++ b/utils.py
@@ -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,