Added "owner" as an additional command permission

This commit is contained in:
Profitroll 2023-01-05 12:42:15 +01:00
parent 19fc9308e4
commit 2e8277d6d2

View File

@ -105,6 +105,7 @@ async def commands_register():
commands = { commands = {
"users": [], "users": [],
"admins": [], "admins": [],
"owner": [],
"group_users": [], "group_users": [],
"group_admins": [], "group_admins": [],
"locales": {} "locales": {}
@ -113,6 +114,7 @@ async def commands_register():
commands_raw = { commands_raw = {
"users": [], "users": [],
"admins": [], "admins": [],
"owner": [],
"group_users": [], "group_users": [],
"group_admins": [], "group_admins": [],
"locales": {} "locales": {}
@ -127,6 +129,7 @@ async def commands_register():
commands["locales"][".".join(entry.split(".")[:-1])] = { commands["locales"][".".join(entry.split(".")[:-1])] = {
"users": [], "users": [],
"admins": [], "admins": [],
"owner": [],
"group_users": [], "group_users": [],
"group_admins": [] "group_admins": []
} }
@ -134,6 +137,7 @@ async def commands_register():
commands_raw["locales"][".".join(entry.split(".")[:-1])] = { commands_raw["locales"][".".join(entry.split(".")[:-1])] = {
"users": [], "users": [],
"admins": [], "admins": [],
"owner": [],
"group_users": [], "group_users": [],
"group_admins": [] "group_admins": []
} }
@ -181,17 +185,23 @@ async def commands_register():
await app.set_bot_commands(commands["locales"][lc]["users"], language_code=lc) await app.set_bot_commands(commands["locales"][lc]["users"], language_code=lc)
logWrite(f"Registered user commands for locale {lc}") logWrite(f"Registered user commands for locale {lc}")
# Registering admin/owner commands # Registering admin commands
for admin in configGet("admins").extend([configGet("owner")]): for admin in configGet("admins"):
try: try:
await app.set_bot_commands(commands["admins"].extend(commands["users"]), 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:
logWrite(f"Registered admin commands for admin {admin}") logWrite(f"Registered admin commands for admin {admin}")
except bad_request_400.PeerIdInvalid: except bad_request_400.PeerIdInvalid:
pass pass
# Registering owner commands
try:
await app.set_bot_commands(commands["admins"]+commands["owner"]+commands["users"], scope=BotCommandScopeChat(chat_id=configGet("owner")))
for lc in valid_locales:
await app.set_bot_commands(commands["locales"][lc]["admins"]+commands["locales"][lc]["owner"]+commands["locales"][lc]["users"], scope=BotCommandScopeChat(chat_id=configGet("owner")))
logWrite(f"Registered admin commands for owner {configGet('owner')}")
except bad_request_400.PeerIdInvalid:
pass
# Registering admin group commands # Registering admin group commands
try: try:
await app.set_bot_commands(commands["group_admins"], scope=BotCommandScopeChat(chat_id=configGet("admin", "groups"))) await app.set_bot_commands(commands["group_admins"], scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))