misc: drop using instace for add_cmd in plugins
This commit is contained in:
@@ -2,10 +2,10 @@ import asyncio
|
||||
|
||||
from pyrogram.types import User
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
@bot.add_cmd(cmd=["ban", "unban"])
|
||||
@BOT.add_cmd(cmd=["ban", "unban"])
|
||||
async def ban_or_unban(bot: BOT, message: Message) -> None:
|
||||
user, reason = await message.extract_user_n_reason()
|
||||
if not isinstance(user, User):
|
||||
@@ -23,7 +23,7 @@ async def ban_or_unban(bot: BOT, message: Message) -> None:
|
||||
await message.reply(text=e, del_in=10)
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="kick")
|
||||
@BOT.add_cmd(cmd="kick")
|
||||
async def kick_user(bot: BOT, message: Message):
|
||||
user, reason = await message.extract_user_n_reason()
|
||||
if not isinstance(user, User):
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from pyrogram.types import ChatPermissions, User
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
@bot.add_cmd(cmd=["mute", "unmute"])
|
||||
@BOT.add_cmd(cmd=["mute", "unmute"])
|
||||
async def mute_or_unmute(bot: BOT, message: Message):
|
||||
user, reason = await message.extract_user_n_reason()
|
||||
if not isinstance(user, User):
|
||||
|
||||
@@ -3,7 +3,7 @@ import asyncio
|
||||
from pyrogram.enums import ChatMemberStatus
|
||||
from pyrogram.types import ChatPrivileges, User
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
DEMOTE_PRIVILEGES = ChatPrivileges(can_manage_chat=False)
|
||||
|
||||
@@ -20,7 +20,7 @@ NO_PRIVILEGES = ChatPrivileges(
|
||||
)
|
||||
|
||||
|
||||
@bot.add_cmd(cmd=["promote", "demote"])
|
||||
@BOT.add_cmd(cmd=["promote", "demote"])
|
||||
async def promote_or_demote(bot: BOT, message: Message) -> None:
|
||||
"""
|
||||
CMD: PROMOTE | DEMOTE
|
||||
|
||||
@@ -2,13 +2,8 @@ import asyncio
|
||||
import os
|
||||
import time
|
||||
|
||||
from ub_core.utils import (
|
||||
Download,
|
||||
DownloadedFile,
|
||||
bytes_to_mb,
|
||||
get_tg_media_details,
|
||||
progress,
|
||||
)
|
||||
from ub_core.utils import (Download, DownloadedFile, get_tg_media_details,
|
||||
progress)
|
||||
|
||||
from app import BOT, Message, bot
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
from ub_core.utils import run_shell_cmd
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="extupdate", allow_sudo=False)
|
||||
@BOT.add_cmd(cmd="extupdate", allow_sudo=False)
|
||||
async def extra_modules_updater(bot: BOT, message: Message):
|
||||
output = await run_shell_cmd(
|
||||
cmd="cd app/modules && git pull", timeout=10, ret_val="0"
|
||||
)
|
||||
|
||||
await message.reply(output)
|
||||
|
||||
if output.strip() != "Already up to date.":
|
||||
bot.raise_sigint()
|
||||
|
||||
@@ -8,7 +8,7 @@ from urllib.parse import urlparse
|
||||
|
||||
from ub_core.utils import MediaExts, aio, run_shell_cmd
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
domains = [
|
||||
"www.youtube.com",
|
||||
@@ -20,7 +20,7 @@ domains = [
|
||||
]
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="song")
|
||||
@BOT.add_cmd(cmd="song")
|
||||
async def song_dl(bot: BOT, message: Message) -> None | Message:
|
||||
reply_query = None
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from app import BOT, Config, CustomDB, Message, bot
|
||||
from app import BOT, Config, CustomDB, Message
|
||||
|
||||
DB = CustomDB("SUDO_CMD_LIST")
|
||||
|
||||
@@ -10,7 +10,7 @@ async def init_task():
|
||||
cmd_object.loaded = True
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="addscmd", allow_sudo=False)
|
||||
@BOT.add_cmd(cmd="addscmd", allow_sudo=False)
|
||||
async def add_scmd(bot: BOT, message: Message):
|
||||
"""
|
||||
CMD: ADDSCMD
|
||||
@@ -21,38 +21,50 @@ async def add_scmd(bot: BOT, message: Message):
|
||||
"""
|
||||
if "-all" in message.flags:
|
||||
cmds = []
|
||||
|
||||
for cmd_name, cmd_object in Config.CMD_DICT.items():
|
||||
if cmd_object.sudo:
|
||||
cmd_object.loaded = True
|
||||
cmds.append({"_id": cmd_name})
|
||||
|
||||
await DB.drop()
|
||||
await DB.insert_many(cmds)
|
||||
|
||||
await (await message.reply("All Commands Added to Sudo!")).log()
|
||||
return
|
||||
|
||||
cmd_name = message.filtered_input
|
||||
response = await message.reply(f"Adding <b>{cmd_name}</b> to sudo....")
|
||||
cmd_object = Config.CMD_DICT.get(cmd_name)
|
||||
|
||||
response = await message.reply(f"Adding <b>{cmd_name}</b> to sudo....")
|
||||
|
||||
if not cmd_object:
|
||||
await response.edit(text=f"<b>{cmd_name}</b> not a valid command.", del_in=10)
|
||||
return
|
||||
|
||||
elif not cmd_object.sudo:
|
||||
await response.edit(
|
||||
text=f"<b>{cmd_name}</b> is disabled for sudo users.", del_in=10
|
||||
)
|
||||
return
|
||||
|
||||
elif cmd_object.loaded:
|
||||
await response.edit(text=f"<b>{cmd_name}</b> already in Sudo!", del_in=10)
|
||||
return
|
||||
|
||||
resp_str = f"#SUDO\n<b>{cmd_name}</b> added to Sudo!"
|
||||
|
||||
if "-temp" in message.flags:
|
||||
resp_str += "\nTemp: True"
|
||||
else:
|
||||
await DB.add_data(data={"_id": cmd_name})
|
||||
|
||||
cmd_object.loaded = True
|
||||
|
||||
await (await response.edit(resp_str)).log()
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="delscmd", allow_sudo=False)
|
||||
@BOT.add_cmd(cmd="delscmd", allow_sudo=False)
|
||||
async def del_scmd(bot: BOT, message: Message):
|
||||
"""
|
||||
CMD: DELSCMD
|
||||
@@ -62,34 +74,45 @@ async def del_scmd(bot: BOT, message: Message):
|
||||
.delscmd ping | .delscmd -all
|
||||
"""
|
||||
if "-all" in message.flags:
|
||||
|
||||
for cmd_object in Config.CMD_DICT.values():
|
||||
cmd_object.loaded = False
|
||||
|
||||
await DB.drop()
|
||||
await (await message.reply("All Commands Removed from Sudo!")).log()
|
||||
return
|
||||
|
||||
cmd_name = message.filtered_input
|
||||
cmd_object = Config.CMD_DICT.get(cmd_name)
|
||||
|
||||
if not cmd_object:
|
||||
return
|
||||
|
||||
response = await message.reply(f"Removing <b>{cmd_name}</b> from sudo....")
|
||||
|
||||
if not cmd_object.loaded:
|
||||
await response.edit(f"<b>{cmd_name}</b> not in Sudo!")
|
||||
return
|
||||
|
||||
cmd_object.loaded = False
|
||||
resp_str = f"#SUDO\n<b>{cmd_name}</b> removed from Sudo!"
|
||||
|
||||
if "-temp" in message.flags:
|
||||
resp_str += "\nTemp: True"
|
||||
else:
|
||||
await DB.delete_data(cmd_name)
|
||||
|
||||
await (await response.edit(resp_str)).log()
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="vscmd")
|
||||
@BOT.add_cmd(cmd="vscmd")
|
||||
async def view_sudo_cmd(bot: BOT, message: Message):
|
||||
cmds = [cmd_name for cmd_name, cmd_obj in Config.CMD_DICT.items() if cmd_obj.loaded]
|
||||
|
||||
if not cmds:
|
||||
await message.reply("No Commands in SUDO!")
|
||||
return
|
||||
|
||||
await message.reply(
|
||||
text=f"List of <b>{len(cmds)}</b>:\n <pre language=json>{cmds}</pre>",
|
||||
del_in=30,
|
||||
|
||||
@@ -4,13 +4,17 @@ from app import BOT, Config, Message, bot
|
||||
from app.plugins.sudo.users import SUDO_USERS
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="disable_su", allow_sudo=False)
|
||||
@BOT.add_cmd(cmd="disable_su", allow_sudo=False)
|
||||
async def disable_su(bot: BOT, message: Message):
|
||||
u_id = message.from_user.id
|
||||
|
||||
if u_id in Config.DISABLED_SUPERUSERS:
|
||||
return
|
||||
|
||||
Config.DISABLED_SUPERUSERS.append(u_id)
|
||||
|
||||
await SUDO_USERS.add_data({"_id": u_id, "disabled": True})
|
||||
|
||||
await message.reply(
|
||||
text="Your <b>SuperUser</b> Access is now <code>Disabled</code>.", del_in=10
|
||||
)
|
||||
@@ -22,13 +26,17 @@ async def disable_su(bot: BOT, message: Message):
|
||||
lambda _, __, m: m.from_user and m.from_user.id in Config.DISABLED_SUPERUSERS
|
||||
),
|
||||
group=1,
|
||||
is_command=True,
|
||||
filters_edited=True,
|
||||
check_for_reactions=True,
|
||||
)
|
||||
async def enable_su(bot: BOT, message: Message):
|
||||
message = Message.parse(message)
|
||||
u_id = message.from_user.id
|
||||
|
||||
Config.DISABLED_SUPERUSERS.remove(u_id)
|
||||
|
||||
await SUDO_USERS.add_data({"_id": u_id, "disabled": False})
|
||||
|
||||
await message.reply(
|
||||
text="Your <b>SuperUser</b> Access is now <code>Enabled</code>.", del_in=10
|
||||
)
|
||||
message.stop_propagation()
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import asyncio
|
||||
|
||||
from pyrogram.types import User
|
||||
from ub_core.utils.helpers import extract_user_data, get_name
|
||||
|
||||
from app import BOT, Config, CustomDB, Message, bot
|
||||
from app import BOT, Config, CustomDB, Message
|
||||
|
||||
SUDO = CustomDB("COMMON_SETTINGS")
|
||||
SUDO_USERS = CustomDB("SUDO_USERS")
|
||||
@@ -12,14 +11,16 @@ SUDO_USERS = CustomDB("SUDO_USERS")
|
||||
async def init_task():
|
||||
sudo = await SUDO.find_one({"_id": "sudo_switch"}) or {}
|
||||
Config.SUDO = sudo.get("value", False)
|
||||
|
||||
async for sudo_user in SUDO_USERS.find():
|
||||
config = Config.SUPERUSERS if sudo_user.get("super") else Config.SUDO_USERS
|
||||
config.append(sudo_user["_id"])
|
||||
|
||||
if sudo_user.get("disabled"):
|
||||
Config.DISABLED_SUPERUSERS.append(sudo_user["_id"])
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="sudo", allow_sudo=False)
|
||||
@BOT.add_cmd(cmd="sudo", allow_sudo=False)
|
||||
async def sudo(bot: BOT, message: Message):
|
||||
"""
|
||||
CMD: SUDO
|
||||
@@ -31,15 +32,19 @@ async def sudo(bot: BOT, message: Message):
|
||||
if "-c" in message.flags:
|
||||
await message.reply(text=f"Sudo is enabled: <b>{Config.SUDO}</b>!", del_in=8)
|
||||
return
|
||||
|
||||
value = not Config.SUDO
|
||||
|
||||
Config.SUDO = value
|
||||
await asyncio.gather(
|
||||
SUDO.add_data({"_id": "sudo_switch", "value": value}),
|
||||
message.reply(text=f"Sudo is enabled: <b>{value}</b>!", del_in=8),
|
||||
)
|
||||
|
||||
await SUDO.add_data({"_id": "sudo_switch", "value": value})
|
||||
|
||||
await (
|
||||
await message.reply(text=f"Sudo is enabled: <b>{value}</b>!", del_in=8)
|
||||
).log()
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="addsudo", allow_sudo=False)
|
||||
@BOT.add_cmd(cmd="addsudo", allow_sudo=False)
|
||||
async def add_sudo(bot: BOT, message: Message) -> Message | None:
|
||||
"""
|
||||
CMD: ADDSUDO
|
||||
@@ -51,23 +56,30 @@ async def add_sudo(bot: BOT, message: Message) -> Message | None:
|
||||
.addsudo [-temp | -su] [ UID | @ | Reply to Message ]
|
||||
"""
|
||||
response = await message.reply("Extracting User info...")
|
||||
|
||||
user, _ = await message.extract_user_n_reason()
|
||||
|
||||
if not isinstance(user, User):
|
||||
await response.edit("unable to extract user info.")
|
||||
return
|
||||
|
||||
if "-su" in message.flags:
|
||||
add_list, remove_list = Config.SUPERUSERS, Config.SUDO_USERS
|
||||
text = "Super Users"
|
||||
else:
|
||||
add_list, remove_list = Config.SUDO_USERS, Config.SUPERUSERS
|
||||
text = "Sudo Users"
|
||||
|
||||
if user.id in add_list:
|
||||
await response.edit(
|
||||
text=f"{get_name(user)} already in Sudo with same privileges!", del_in=5
|
||||
)
|
||||
return
|
||||
|
||||
response_str = f"#SUDO\n{user.mention} added to {text} List."
|
||||
|
||||
add_and_remove(user.id, add_list, remove_list)
|
||||
|
||||
if "-temp" not in message.flags:
|
||||
await SUDO_USERS.add_data(
|
||||
{
|
||||
@@ -79,11 +91,12 @@ async def add_sudo(bot: BOT, message: Message) -> Message | None:
|
||||
)
|
||||
else:
|
||||
response_str += "\n<b>Temporary</b>: True"
|
||||
|
||||
await response.edit(text=response_str, del_in=5)
|
||||
await response.log()
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="delsudo", allow_sudo=False)
|
||||
@BOT.add_cmd(cmd="delsudo", allow_sudo=False)
|
||||
async def remove_sudo(bot: BOT, message: Message) -> Message | None:
|
||||
"""
|
||||
CMD: DELSUDO
|
||||
@@ -96,15 +109,19 @@ async def remove_sudo(bot: BOT, message: Message) -> Message | None:
|
||||
"""
|
||||
response = await message.reply("Extracting User info...")
|
||||
user, _ = await message.extract_user_n_reason()
|
||||
|
||||
if isinstance(user, str):
|
||||
await response.edit(user)
|
||||
return
|
||||
|
||||
if not isinstance(user, User):
|
||||
await response.edit("unable to extract user info.")
|
||||
return
|
||||
|
||||
if user.id not in {*Config.SUDO_USERS, *Config.SUPERUSERS}:
|
||||
await response.edit(text=f"{get_name(user)} not in Sudo!", del_in=5)
|
||||
return
|
||||
|
||||
if "-su" in message.flags:
|
||||
response_str = f"{user.mention}'s Super User access is revoked to Sudo only."
|
||||
add_and_remove(user.id, Config.SUDO_USERS, Config.SUPERUSERS)
|
||||
@@ -112,13 +129,16 @@ async def remove_sudo(bot: BOT, message: Message) -> Message | None:
|
||||
add_and_remove(user.id, remove_list=Config.SUPERUSERS)
|
||||
add_and_remove(user.id, remove_list=Config.SUDO_USERS)
|
||||
response_str = f"{user.mention}'s access to bot has been removed."
|
||||
|
||||
if "-temp" not in message.flags:
|
||||
if "-su" in message.flags:
|
||||
await SUDO_USERS.add_data({"_id": user.id, "super": False})
|
||||
else:
|
||||
await SUDO_USERS.delete_data(id=user.id)
|
||||
|
||||
else:
|
||||
response_str += "\n<b>Temporary</b>: True"
|
||||
|
||||
await response.edit(text=response_str, del_in=5)
|
||||
await response.log()
|
||||
|
||||
@@ -128,11 +148,12 @@ def add_and_remove(
|
||||
):
|
||||
if add_list is not None and u_id not in add_list:
|
||||
add_list.append(u_id)
|
||||
|
||||
if remove_list is not None and u_id in remove_list:
|
||||
remove_list.remove(u_id)
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="vsudo")
|
||||
@BOT.add_cmd(cmd="vsudo")
|
||||
async def sudo_list(bot: BOT, message: Message):
|
||||
"""
|
||||
CMD: VSUDO
|
||||
@@ -143,15 +164,22 @@ async def sudo_list(bot: BOT, message: Message):
|
||||
"""
|
||||
output: str = ""
|
||||
total = 0
|
||||
|
||||
async for user in SUDO_USERS.find():
|
||||
output += f'\n<b>• {user["name"]}</b>'
|
||||
|
||||
if "-id" in message.flags:
|
||||
output += f'\n ID: <code>{user["_id"]}</code>'
|
||||
|
||||
output += f'\n Super: <b>{user.get("super", False)}</b>'
|
||||
|
||||
output += f'\n Disabled: <b>{user.get("disabled", False)}</b>\n'
|
||||
|
||||
total += 1
|
||||
|
||||
if not total:
|
||||
await message.reply("You don't have any SUDO USERS.")
|
||||
return
|
||||
|
||||
output: str = f"List of <b>{total}</b> SUDO USERS:\n{output}"
|
||||
await message.reply(output, del_in=30, block=True)
|
||||
|
||||
@@ -4,10 +4,10 @@ import os
|
||||
from pyrogram.errors import BadRequest
|
||||
from ub_core.utils import get_name
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="ids")
|
||||
@BOT.add_cmd(cmd="ids")
|
||||
async def get_ids(bot: BOT, message: Message) -> None:
|
||||
reply: Message = message.replied
|
||||
if reply:
|
||||
@@ -33,7 +33,7 @@ async def get_ids(bot: BOT, message: Message) -> None:
|
||||
await message.reply(resp_str)
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="join")
|
||||
@BOT.add_cmd(cmd="join")
|
||||
async def join_chat(bot: BOT, message: Message) -> None:
|
||||
chat: str = message.input
|
||||
try:
|
||||
@@ -47,7 +47,7 @@ async def join_chat(bot: BOT, message: Message) -> None:
|
||||
await message.reply("Joined")
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="leave")
|
||||
@BOT.add_cmd(cmd="leave")
|
||||
async def leave_chat(bot: BOT, message: Message) -> None:
|
||||
if message.input:
|
||||
chat = message.input
|
||||
@@ -58,7 +58,7 @@ async def leave_chat(bot: BOT, message: Message) -> None:
|
||||
del_in=5,
|
||||
block=True,
|
||||
)
|
||||
await asyncio.sleep(2)
|
||||
await asyncio.sleep(5)
|
||||
try:
|
||||
await bot.leave_chat(chat)
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="click")
|
||||
@BOT.add_cmd(cmd="click")
|
||||
async def click(bot: BOT, message: Message):
|
||||
if not message.input or not message.replied:
|
||||
await message.reply(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
from app.plugins.tg_tools.get_message import parse_link
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="del")
|
||||
@BOT.add_cmd(cmd="del")
|
||||
async def delete_message(bot: BOT, message: Message) -> None:
|
||||
"""
|
||||
CMD: DEL
|
||||
@@ -18,7 +18,7 @@ async def delete_message(bot: BOT, message: Message) -> None:
|
||||
await message.delete(reply=True)
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="purge")
|
||||
@BOT.add_cmd(cmd="purge")
|
||||
async def purge_(bot: BOT, message: Message) -> None | Message:
|
||||
start_message: int = message.reply_id
|
||||
if not start_message:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
def parse_link(link: str) -> tuple[int | str, int]:
|
||||
@@ -11,7 +11,7 @@ def parse_link(link: str) -> tuple[int | str, int]:
|
||||
return chat, int(id)
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="gm")
|
||||
@BOT.add_cmd(cmd="gm")
|
||||
async def get_message(bot: BOT, message: Message):
|
||||
"""
|
||||
CMD: Get Message
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from datetime import datetime
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
# Not my Code
|
||||
# Prolly from Userge/UX/VenomX IDK
|
||||
@bot.add_cmd(cmd="ping")
|
||||
@BOT.add_cmd(cmd="ping")
|
||||
async def ping_bot(bot: BOT, message: Message):
|
||||
start = datetime.now()
|
||||
resp: Message = await message.reply("Checking Ping.....")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
from app.plugins.tg_tools.get_message import parse_link
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="reply")
|
||||
@BOT.add_cmd(cmd="reply")
|
||||
async def reply(bot: BOT, message: Message) -> None:
|
||||
"""
|
||||
CMD: REPLY
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import re
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="resp")
|
||||
@BOT.add_cmd(cmd="resp")
|
||||
async def respond(bot: BOT, message: Message):
|
||||
"""
|
||||
CMD: RESP
|
||||
|
||||
Reference in New Issue
Block a user