diff --git a/commands/bot.py b/commands/bot.py index cbcf4a9..6fe922f 100644 --- a/commands/bot.py +++ b/commands/bot.py @@ -6,6 +6,15 @@ import utils from state import start_time +async def help(message): + await utils.reply( + message, + ", ".join( + [f"`{command.value}`" for command in commands.Command.__members__.values()] + ), + ) + + async def uptime(message): tokens = commands.tokenize(message.content) parser = arguments.ArgumentParser( diff --git a/commands/utils.py b/commands/utils.py index 85cb9de..631c39f 100644 --- a/commands/utils.py +++ b/commands/utils.py @@ -6,6 +6,7 @@ import constants class Command(enum.Enum): CLEAR = "clear" EXECUTE = "execute" + HELP = "help" JOIN = "join" LEAVE = "leave" PAUSE = "pause" diff --git a/commands/voice.py b/commands/voice.py index 45fa3b0..6cda49c 100644 --- a/commands/voice.py +++ b/commands/voice.py @@ -178,10 +178,7 @@ async def volume(message): if args.volume: message.guild.voice_client.source.volume = float(args.volume) / 100.0 - await utils.reply( - message, - f"{args.volume}", - ) + await utils.add_check_reaction(message) else: await utils.reply( message, diff --git a/constants.py b/constants.py index d81f69e..66c283a 100644 --- a/constants.py +++ b/constants.py @@ -1,10 +1,18 @@ import os -import sys EMBED_COLOR = 0xFF6600 OWNERS = [531392146767347712] PREFIX = "%" -RELOAD_BLACKLISTED_MODULES = [*sys.builtin_module_names] +RELOADABLE_MODULES = [ + "arguments", + "commands", + "constants", + "core", + "events", + "utils", + "voice", + "ytdlp", +] YTDL_OPTIONS = { "default_search": "auto", diff --git a/core.py b/core.py index ed96e5d..4718981 100644 --- a/core.py +++ b/core.py @@ -9,6 +9,7 @@ import disnake_paginator import commands import constants +import core import utils @@ -30,6 +31,16 @@ async def on_message(message): C = commands.Command try: match matched[0]: + case C.RELOAD if message.author.id in constants.OWNERS: + reloaded_modules = set() + for module in filter( + lambda v: inspect.ismodule(v) + and v.__name__ in constants.RELOADABLE_MODULES, + globals().values(), + ): + core.rreload(reloaded_modules, module) + + await utils.add_check_reaction(message) case C.EXECUTE if message.author.id in constants.OWNERS: code = message.content[len(tokens[0]) + 1 :].strip().strip("`") for replacement in ["python", "py"]: @@ -91,6 +102,8 @@ async def on_message(message): await commands.voice.pause(message) case C.VOLUME: await commands.voice.volume(message) + case C.HELP: + await commands.bot.help(message) case C.UPTIME: await commands.bot.uptime(message) except Exception as e: @@ -101,22 +114,16 @@ async def on_message(message): def rreload(reloaded_modules, module): - reloaded_modules.add(module) + reloaded_modules.add(module.__name__) importlib.reload(module) if "__reload_module__" in dir(module): module.__reload_module__() with contextlib.suppress(AttributeError): - for module in filter( - lambda m: m.__spec__.origin != "frozen", - filter( - lambda v: inspect.ismodule(v) - and ( - v.__name__.split(".")[-1] - not in constants.RELOAD_BLACKLISTED_MODULES - ) - and (v not in reloaded_modules), - map(lambda attr: getattr(module, attr), dir(module)), - ), + for submodule in filter( + lambda v: inspect.ismodule(v) + and (v.__name__.split(".")[-1] in constants.RELOADABLE_MODULES) + and v.__name__ not in reloaded_modules, + map(lambda attr: getattr(module, attr), dir(module)), ): - rreload(reloaded_modules, module) + rreload(reloaded_modules, submodule) diff --git a/main.py b/main.py index 0a9031f..4a791bd 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,8 @@ -import inspect import time -import commands import constants import core import events -import utils from state import client, start_time @@ -25,25 +22,9 @@ async def on_message_edit(before, after): async def on_message(message): await events.trigger_dynamic_handlers("on_message", message) - global reloaded_modules - if not message.content.startswith(constants.PREFIX): return - if message.author.id in constants.OWNERS and commands.match(message.content) == [ - commands.Command.RELOAD - ]: - reloaded_modules = set() - for module in filter( - lambda v: inspect.ismodule(v) - and v.__name__ not in constants.RELOAD_BLACKLISTED_MODULES, - globals().values(), - ): - core.rreload(reloaded_modules, module) - - await utils.add_check_reaction(message) - return - await core.on_message(message)