From a9b5685d7bc0c27d599941961141e6131f2d543f Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 1 Dec 2022 11:27:33 +0100 Subject: [PATCH] Improved rules --- locale/uk.json | 4 ++- main.py | 80 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/locale/uk.json b/locale/uk.json index f33a6a4..674d44e 100644 --- a/locale/uk.json +++ b/locale/uk.json @@ -116,7 +116,9 @@ "reapply_yes": "✅ Прийняти", "reapply_no": "❌ Відхилити", "rules_home": "🏠 Головна", - "rules_additional": "➕ Додаткові" + "rules_additional": "➕ Додаткові", + "rules_next": "Далі ➡️", + "rules_prev": "⬅️ Назад" }, "callback": { "sub_accepted": "✅ Анкету {0} схвалено", diff --git a/main.py b/main.py index 0d5207d..4f6df9c 100644 --- a/main.py +++ b/main.py @@ -62,32 +62,33 @@ async def cmd_kill(app, msg): # Rules command ============================================================================================================= +default_rules_markup = InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton(locale("rules_home", "button"), callback_data="rules_home"), + InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional") + ], + [ + InlineKeyboardButton("1", callback_data="rule_1"), + InlineKeyboardButton("2", callback_data="rule_2"), + InlineKeyboardButton("3", callback_data="rule_3") + ], + [ + InlineKeyboardButton("4", callback_data="rule_4"), + InlineKeyboardButton("5", callback_data="rule_5"), + InlineKeyboardButton("6", callback_data="rule_6") + ], + [ + InlineKeyboardButton("7", callback_data="rule_7"), + InlineKeyboardButton("8", callback_data="rule_8"), + InlineKeyboardButton("9", callback_data="rule_9") + ] + ] +) + @app.on_message(~ filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"])) async def cmd_rules(app, msg): - await msg.reply_text(locale("rules_msg"), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup( - [ - [ - InlineKeyboardButton(locale("rules_home", "button"), callback_data="rules_home"), - InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional") - ], - [ - InlineKeyboardButton("1", callback_data="rule_1"), - InlineKeyboardButton("2", callback_data="rule_2"), - InlineKeyboardButton("3", callback_data="rule_3") - ], - [ - InlineKeyboardButton("4", callback_data="rule_4"), - InlineKeyboardButton("5", callback_data="rule_5"), - InlineKeyboardButton("6", callback_data="rule_6") - ], - [ - InlineKeyboardButton("7", callback_data="rule_7"), - InlineKeyboardButton("8", callback_data="rule_8"), - InlineKeyboardButton("9", callback_data="rule_9") - ] - ] - ) - ) + await msg.reply_text(locale("rules_msg"), disable_web_page_preview=True, reply_markup=default_rules_markup) # for rule_msg in locale("rules"): # await msg.reply_text(rule_msg) # ============================================================================================================================== @@ -566,8 +567,33 @@ async def callback_query_rule(app, clb): logWrite(f"User {clb.from_user.id} requested to check out rule {fullclb[1]}") + rule_num = int(fullclb[1]) + + if rule_num == len(locale("rules")): + lower_buttons = [ + InlineKeyboardButton(locale("rules_prev", "button"), callback_data=f"rule_{rule_num-1}") + ] + elif rule_num == 1: + lower_buttons = [ + InlineKeyboardButton(locale("rules_next", "button"), callback_data=f"rule_{rule_num+1}") + ] + else: + lower_buttons = [ + InlineKeyboardButton(locale("rules_prev", "button"), callback_data=f"rule_{rule_num-1}"), + InlineKeyboardButton(locale("rules_next", "button"), callback_data=f"rule_{rule_num+1}") + ] + try: - await clb.message.edit(text=locale("rules")[int(fullclb[1])-1], disable_web_page_preview=True, reply_markup=clb.message.reply_markup) + await clb.message.edit(text=locale("rules")[rule_num-1], disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton(locale("rules_home", "button"), callback_data="rules_home"), + InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional") + ], + lower_buttons + ] + ) + ) except bad_request_400.MessageNotModified: pass @@ -579,7 +605,7 @@ async def callback_query_rules_home(app, clb): logWrite(f"User {clb.from_user.id} requested to check out homepage rules") try: - await clb.message.edit(text=locale("rules_msg"), disable_web_page_preview=True, reply_markup=clb.message.reply_markup) + await clb.message.edit(text=locale("rules_msg"), disable_web_page_preview=True, reply_markup=default_rules_markup) except bad_request_400.MessageNotModified: pass @@ -591,7 +617,7 @@ async def callback_query_rules_additional(app, clb): logWrite(f"User {clb.from_user.id} requested to check out additional rules") try: - await clb.message.edit(text=locale("rules_additional"), disable_web_page_preview=True, reply_markup=clb.message.reply_markup) + await clb.message.edit(text=locale("rules_additional"), disable_web_page_preview=True, reply_markup=default_rules_markup) except bad_request_400.MessageNotModified: pass