Improved rules

This commit is contained in:
Profitroll 2022-12-01 11:27:33 +01:00
parent 97325b4ff5
commit a9b5685d7b
2 changed files with 56 additions and 28 deletions

View File

@ -116,7 +116,9 @@
"reapply_yes": "✅ Прийняти", "reapply_yes": "✅ Прийняти",
"reapply_no": "❌ Відхилити", "reapply_no": "❌ Відхилити",
"rules_home": "🏠 Головна", "rules_home": "🏠 Головна",
"rules_additional": " Додаткові" "rules_additional": " Додаткові",
"rules_next": "Далі ➡️",
"rules_prev": "⬅️ Назад"
}, },
"callback": { "callback": {
"sub_accepted": "✅ Анкету {0} схвалено", "sub_accepted": "✅ Анкету {0} схвалено",

40
main.py
View File

@ -62,9 +62,7 @@ async def cmd_kill(app, msg):
# Rules command ============================================================================================================= # Rules command =============================================================================================================
@app.on_message(~ filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"])) default_rules_markup = InlineKeyboardMarkup(
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_home", "button"), callback_data="rules_home"),
@ -87,7 +85,10 @@ async def cmd_rules(app, msg):
] ]
] ]
) )
)
@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=default_rules_markup)
# for rule_msg in locale("rules"): # for rule_msg in locale("rules"):
# await msg.reply_text(rule_msg) # 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]}") 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: 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: except bad_request_400.MessageNotModified:
pass 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") logWrite(f"User {clb.from_user.id} requested to check out homepage rules")
try: 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: except bad_request_400.MessageNotModified:
pass 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") logWrite(f"User {clb.from_user.id} requested to check out additional rules")
try: 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: except bad_request_400.MessageNotModified:
pass pass