Compare commits
2 Commits
c90495eb1c
...
2e8277d6d2
Author | SHA1 | Date | |
---|---|---|---|
2e8277d6d2 | |||
19fc9308e4 |
@ -149,8 +149,7 @@
|
||||
},
|
||||
"reboot": {
|
||||
"permissions": [
|
||||
"admins",
|
||||
"group_admins"
|
||||
"owner"
|
||||
],
|
||||
"modules": [
|
||||
"general"
|
||||
@ -201,6 +200,14 @@
|
||||
"modules": [
|
||||
"applications"
|
||||
]
|
||||
},
|
||||
"resetcommands": {
|
||||
"permissions": [
|
||||
"owner"
|
||||
],
|
||||
"modules": [
|
||||
"general"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ from modules.commands.message import *
|
||||
from modules.commands.nearby import *
|
||||
from modules.commands.reapply import *
|
||||
from modules.commands.reboot import *
|
||||
from modules.commands.resetcommands import *
|
||||
from modules.commands.rules import *
|
||||
from modules.commands.spoiler import *
|
||||
from modules.commands.sponsorship import *
|
||||
|
@ -275,6 +275,7 @@
|
||||
"nearby": "Показати користувачів поблизу",
|
||||
"reapply": "Повторно заповнити анкету",
|
||||
"reboot": "Перезапустити бота",
|
||||
"resetcommands": "Відреєструвати всі команди",
|
||||
"rules": "Правила спільноти",
|
||||
"spoiler": "Почати створювати спойлер",
|
||||
"sponsorship": "Отримати роль за спонсорство",
|
||||
|
65
modules/commands/resetcommands.py
Normal file
65
modules/commands/resetcommands.py
Normal file
@ -0,0 +1,65 @@
|
||||
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()
|
||||
|
||||
# Shutdown command =============================================================================================================
|
||||
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["resetcommands"], prefixes=["/"]) & custom_filters.admin)
|
||||
async def cmd_kill(app: Client, msg: Message):
|
||||
|
||||
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]))
|
||||
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}')
|
||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))
|
||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
|
||||
|
||||
for admin in configGet("admins"):
|
||||
try:
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands for admin {admin}')
|
||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin))
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
pass
|
||||
|
||||
try:
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands for owner {configGet("owner")}')
|
||||
for lc in valid_locales:
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]')
|
||||
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:
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands for locale {lc}')
|
||||
await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc)
|
||||
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting default commands')
|
||||
await app.delete_bot_commands()
|
||||
|
||||
await msg.reply_text("OK", quote=should_quote(msg))
|
||||
|
||||
if configGet("debug") is True:
|
||||
logWrite(str(await app.get_bot_commands()))
|
||||
logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))))
|
||||
# ==============================================================================================================================
|
@ -105,6 +105,7 @@ async def commands_register():
|
||||
commands = {
|
||||
"users": [],
|
||||
"admins": [],
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": [],
|
||||
"locales": {}
|
||||
@ -113,6 +114,7 @@ async def commands_register():
|
||||
commands_raw = {
|
||||
"users": [],
|
||||
"admins": [],
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": [],
|
||||
"locales": {}
|
||||
@ -127,6 +129,7 @@ async def commands_register():
|
||||
commands["locales"][".".join(entry.split(".")[:-1])] = {
|
||||
"users": [],
|
||||
"admins": [],
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": []
|
||||
}
|
||||
@ -134,6 +137,7 @@ async def commands_register():
|
||||
commands_raw["locales"][".".join(entry.split(".")[:-1])] = {
|
||||
"users": [],
|
||||
"admins": [],
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": []
|
||||
}
|
||||
@ -181,17 +185,23 @@ async def commands_register():
|
||||
await app.set_bot_commands(commands["locales"][lc]["users"], language_code=lc)
|
||||
logWrite(f"Registered user commands for locale {lc}")
|
||||
|
||||
# Registering admin/owner commands
|
||||
for admin in configGet("admins").extend([configGet("owner")]):
|
||||
# Registering admin commands
|
||||
for admin in configGet("admins"):
|
||||
try:
|
||||
await app.set_bot_commands(commands["admins"].extend(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}")
|
||||
await app.set_bot_commands(commands["admins"]+commands["users"], scope=BotCommandScopeChat(chat_id=admin))
|
||||
logWrite(f"Registered admin commands for admin {admin}")
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
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
|
||||
try:
|
||||
await app.set_bot_commands(commands["group_admins"], scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))
|
||||
|
Reference in New Issue
Block a user