Spoilers, major command system improvements #4
@ -4,6 +4,7 @@ some scheduled tasks is the main idea of this module"""
|
||||
from os import listdir, makedirs, path, sep
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from datetime import datetime, timedelta
|
||||
from ujson import dumps
|
||||
from app import app
|
||||
from pyrogram.types import BotCommand, BotCommandScopeChat
|
||||
from pyrogram.errors import bad_request_400
|
||||
@ -109,6 +110,14 @@ async def commands_register():
|
||||
"locales": {}
|
||||
}
|
||||
|
||||
commands_raw = {
|
||||
"users": [],
|
||||
"admins": [],
|
||||
"group_users": [],
|
||||
"group_admins": [],
|
||||
"locales": {}
|
||||
}
|
||||
|
||||
valid_locales = []
|
||||
files_locales = listdir(f'{configGet("locale", "locations")}')
|
||||
|
||||
@ -121,6 +130,13 @@ async def commands_register():
|
||||
"group_users": [],
|
||||
"group_admins": []
|
||||
}
|
||||
if configGet("debug") is True:
|
||||
commands_raw["locales"][".".join(entry.split(".")[:-1])] = {
|
||||
"users": [],
|
||||
"admins": [],
|
||||
"group_users": [],
|
||||
"group_admins": []
|
||||
}
|
||||
|
||||
config_modules = configGet("features")
|
||||
config_commands = configGet("commands")
|
||||
@ -135,13 +151,26 @@ async def commands_register():
|
||||
enabled = True
|
||||
|
||||
if enabled is False:
|
||||
if configGet("debug") is True:
|
||||
logWrite(f"Not registering {command} at all")
|
||||
continue
|
||||
|
||||
for permission in config_commands[command]["permissions"]:
|
||||
|
||||
commands[permission].append(BotCommand(command, locale("commands")[command]))
|
||||
|
||||
if configGet("debug") is True:
|
||||
commands_raw[permission].append({f"{command}": locale("commands")[command]})
|
||||
logWrite(f"Registering {command} for {permission}")
|
||||
|
||||
for lc in valid_locales:
|
||||
|
||||
commands["locales"][lc][permission].append(BotCommand(command, locale("commands", locale=lc)[command]))
|
||||
|
||||
if configGet("debug") is True:
|
||||
commands_raw["locales"][lc][permission].append({f"{command}": locale("commands", locale=lc)[command]})
|
||||
logWrite(f"Registering {command} for {permission} [{lc}]")
|
||||
|
||||
|
||||
# Registering user commands
|
||||
await app.set_bot_commands(commands["users"])
|
||||
@ -155,7 +184,7 @@ async def commands_register():
|
||||
# Registering admin/owner commands
|
||||
for admin in configGet("admins")+[configGet("owner")]:
|
||||
try:
|
||||
await app.set_bot_commands(commands["admins"], scope=BotCommandScopeChat(chat_id=admin))
|
||||
await app.set_bot_commands(commands["admins"]+commands["users"], scope=BotCommandScopeChat(chat_id=admin))
|
||||
if admin == configGet("owner"):
|
||||
logWrite(f"Registered admin commands for owner {configGet('owner')}")
|
||||
else:
|
||||
@ -175,4 +204,8 @@ async def commands_register():
|
||||
await app.set_bot_commands(commands["group_users"], scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
|
||||
logWrite("Registered destination group commands")
|
||||
except bad_request_400.ChannelInvalid:
|
||||
logWrite(f"Could not register commands for destination group. Bot is likely not in the group.")
|
||||
logWrite(f"Could not register commands for destination group. Bot is likely not in the group.")
|
||||
|
||||
|
||||
if configGet("debug") is True:
|
||||
logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}")
|
Reference in New Issue
Block a user