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

106 lines
3.7 KiB
Python
Raw Normal View History

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