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/commands/resetcommands.py

71 lines
3.6 KiB
Python
Raw Normal View History

2023-01-05 13:41:55 +02:00
from app import app
from os import getpid, listdir
from pyrogram import filters
from pyrogram.types import Message, BotCommandScopeDefault, BotCommandScopeChat
from pyrogram.errors import bad_request_400
from pyrogram.client import Client
from modules.utils import logWrite, should_quote, configGet
from modules import custom_filters
pid = getpid()
2023-01-05 14:01:57 +02:00
# Reset commands command =======================================================================================================
2023-01-05 13:41:55 +02:00
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["resetcommands"], prefixes=["/"]) & custom_filters.admin)
2023-01-05 14:01:57 +02:00
async def cmd_resetcommands(app: Client, msg: Message):
2023-01-05 13:41:55 +02:00
if msg.from_user.id == configGet("owner"):
logWrite(f"Resetting all commands on owner's request")
valid_locales = []
files_locales = listdir(f'{configGet("locale", "locations")}')
for entry in files_locales:
if entry.endswith(".json"):
valid_locales.append(".".join(entry.split(".")[:-1]))
2023-01-09 13:39:39 +02:00
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}', debug=True)
2023-01-05 13:41:55 +02:00
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
2023-02-01 15:21:48 +02:00
for lc in valid_locales:
try:
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")} [{lc}]', debug=True)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")), language_code=lc)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")), language_code=lc)
except:
pass
2023-01-05 13:41:55 +02:00
for admin in configGet("admins"):
try:
2023-01-09 13:39:39 +02:00
logWrite(f'Resetting commands for admin {admin}', debug=True)
2023-01-05 13:41:55 +02:00
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin))
2023-02-01 15:21:48 +02:00
for lc in valid_locales:
try:
logWrite(f'Resetting commands for admin {admin} [{lc}]', debug=True)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin), language_code=lc)
except:
pass
2023-01-05 13:41:55 +02:00
except bad_request_400.PeerIdInvalid:
pass
try:
2023-01-09 13:39:39 +02:00
logWrite(f'Resetting commands for owner {configGet("owner")}', debug=True)
2023-01-05 13:41:55 +02:00
for lc in valid_locales:
2023-01-09 13:39:39 +02:00
logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]', debug=True)
2023-01-05 13:41:55 +02:00
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")), language_code=lc)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))
except bad_request_400.PeerIdInvalid:
pass
for lc in valid_locales:
2023-01-09 13:39:39 +02:00
logWrite(f'Resetting commands for locale {lc}', debug=True)
2023-01-05 13:41:55 +02:00
await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc)
2023-01-09 13:39:39 +02:00
logWrite(f'Resetting default commands', debug=True)
2023-01-05 13:41:55 +02:00
await app.delete_bot_commands()
await msg.reply_text("OK", quote=should_quote(msg))
2023-01-09 13:39:39 +02:00
logWrite(str(await app.get_bot_commands()), debug=True)
logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))), debug=True)
2023-01-05 13:41:55 +02:00
# ==============================================================================================================================