Improved rules

This commit is contained in:
Profitroll 2022-11-30 13:02:07 +01:00
parent 9105a0266c
commit 19cc4a2f86
2 changed files with 86 additions and 9 deletions

File diff suppressed because one or more lines are too long

69
main.py
View File

@ -63,8 +63,32 @@ async def cmd_kill(app, msg):
# Rules command ============================================================================================================= # Rules command =============================================================================================================
@app.on_message(~ filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"])) @app.on_message(~ filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"]))
async def cmd_rules(app, msg): async def cmd_rules(app, msg):
for rule_msg in locale("rules"): await msg.reply_text(locale("rules_msg"), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(
await msg.reply_text(rule_msg) [
[
InlineKeyboardButton(locale("rules_home", "button"), callback_data="rules_home"),
InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional")
],
[
InlineKeyboardButton("1", callback_data="rule_1"),
InlineKeyboardButton("2", callback_data="rule_2"),
InlineKeyboardButton("3", callback_data="rule_3")
],
[
InlineKeyboardButton("4", callback_data="rule_4"),
InlineKeyboardButton("5", callback_data="rule_5"),
InlineKeyboardButton("6", callback_data="rule_6")
],
[
InlineKeyboardButton("7", callback_data="rule_7"),
InlineKeyboardButton("8", callback_data="rule_8"),
InlineKeyboardButton("9", callback_data="rule_9")
]
]
)
)
# for rule_msg in locale("rules"):
# await msg.reply_text(rule_msg)
# ============================================================================================================================== # ==============================================================================================================================
@ -533,6 +557,47 @@ async def callback_query_nothing(app, clb):
# ============================================================================================================================== # ==============================================================================================================================
# 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]}")
try:
await clb.message.edit(text=locale("rules")[int(fullclb[1])-1], disable_web_page_preview=True, reply_markup=clb.message.reply_markup)
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=clb.message.reply_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=clb.message.reply_markup)
except bad_request_400.MessageNotModified:
pass
await clb.answer(text=locale("rules_additional", "callback")) # type: ignore
# ==============================================================================================================================
# Contact getting ============================================================================================================== # Contact getting ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.contact & filters.private) @app.on_message(~ filters.scheduled & filters.contact & filters.private)
async def get_contact(app, msg): async def get_contact(app, msg):