This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/callbacks/rules.py
2022-12-27 13:36:54 +01:00

72 lines
3.2 KiB
Python

from app import app
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram.client import Client
from pyrogram.errors import bad_request_400
from pyrogram import filters
from modules.utils import locale, logWrite
from modules.commands.rules import DefaultRulesMarkup
# Callback rule ================================================================================================================
@app.on_callback_query(filters.regex("rule_[\s\S]*"))
async def callback_query_rule(app: Client, clb: CallbackQuery):
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", locale=clb.from_user), callback_data=f"rule_{rule_num-1}")
]
elif rule_num == 1:
lower_buttons = [
InlineKeyboardButton(locale("rules_next", "button", locale=clb.from_user), callback_data=f"rule_{rule_num+1}")
]
else:
lower_buttons = [
InlineKeyboardButton(locale("rules_prev", "button", locale=clb.from_user), callback_data=f"rule_{rule_num-1}"),
InlineKeyboardButton(locale("rules_next", "button", locale=clb.from_user), callback_data=f"rule_{rule_num+1}")
]
try:
await clb.message.edit(text=locale("rules", locale=clb.from_user)[rule_num-1], disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(locale("rules_home", "button", locale=clb.from_user), callback_data="rules_home"),
InlineKeyboardButton(locale("rules_additional", "button", locale=clb.from_user), callback_data="rules_additional")
],
lower_buttons
]
)
)
except bad_request_400.MessageNotModified:
pass
await clb.answer(text=locale("rules_page", "callback", locale=clb.from_user).format(fullclb[1]))
@app.on_callback_query(filters.regex("rules_home"))
async def callback_query_rules_home(app: Client, clb: CallbackQuery):
logWrite(f"User {clb.from_user.id} requested to check out homepage rules")
try:
await clb.message.edit(text=locale("rules_msg", locale=clb.from_user), disable_web_page_preview=True, reply_markup=DefaultRulesMarkup(clb.from_user).keyboard)
except bad_request_400.MessageNotModified:
pass
await clb.answer(text=locale("rules_home", "callback", locale=clb.from_user))
@app.on_callback_query(filters.regex("rules_additional"))
async def callback_query_rules_additional(app: Client, clb: CallbackQuery):
logWrite(f"User {clb.from_user.id} requested to check out additional rules")
try:
await clb.message.edit(text=locale("rules_additional", locale=clb.from_user), disable_web_page_preview=True, reply_markup=DefaultRulesMarkup(clb.from_user).keyboard)
except bad_request_400.MessageNotModified:
pass
await clb.answer(text=locale("rules_additional", "callback", locale=clb.from_user))
# ==============================================================================================================================