from app import app from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton from pyrogram.errors import bad_request_400 from pyrogram import filters from modules.utils import locale, logWrite from modules.commands.rules import default_rules_markup # Callback rule ================================================================================================================ @app.on_callback_query(filters.regex("rule_[\s\S]*")) async def callback_query_rule(app, clb): fullclb = clb.data.split("_") 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")[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 await clb.answer(text=locale("rules_page", "callback").format(fullclb[1])) @app.on_callback_query(filters.regex("rules_home")) 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=default_rules_markup) except bad_request_400.MessageNotModified: pass await clb.answer(text=locale("rules_home", "callback")) @app.on_callback_query(filters.regex("rules_additional")) 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=default_rules_markup) except bad_request_400.MessageNotModified: pass await clb.answer(text=locale("rules_additional", "callback")) # ==============================================================================================================================