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]*")) # type: ignore 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}") # type: ignore ] elif rule_num == 1: lower_buttons = [ InlineKeyboardButton(locale("rules_next", "button"), callback_data=f"rule_{rule_num+1}") # type: ignore ] else: lower_buttons = [ InlineKeyboardButton(locale("rules_prev", "button"), callback_data=f"rule_{rule_num-1}"), # type: ignore InlineKeyboardButton(locale("rules_next", "button"), callback_data=f"rule_{rule_num+1}") # type: ignore ] 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"), # type: ignore InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional") # type: ignore ], lower_buttons ] ) ) except bad_request_400.MessageNotModified: pass await clb.answer(text=locale("rules_page", "callback").format(fullclb[1])) # type: ignore @app.on_callback_query(filters.regex("rules_home")) # type: ignore 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")) # type: ignore @app.on_callback_query(filters.regex("rules_additional")) # type: ignore 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")) # type: ignore # ==============================================================================================================================