diff --git a/commands/loader.py b/commands/loader.py index cab69b1..e885988 100644 --- a/commands/loader.py +++ b/commands/loader.py @@ -12,6 +12,9 @@ def load_commands() -> Dict[str, AbstractCommand]: commands = compile_and_load() return commands +def load_commands_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]: + commands = compile_and_load_new(commandType) + return commands def compile_and_load_file(path: str) -> (str, AbstractCommand): module_name = os.path.split(path)[1].replace(".py", "") @@ -41,6 +44,18 @@ def compile_and_load() -> Dict[str, AbstractCommand]: break return dic +def compile_and_load_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]: + dic = {} + implementations = get_implementations_dir() + for dirName, subdirList, fileList in os.walk(implementations): + for file in fileList: + name = os.path.join(dirName, file) + print("compiling %s" % name) + name, command = compile_and_load_file(name) + if command is not None and command.command_type is commandType: + dic[name] = command + break + return dic def get_base_dir() -> str: cwd = os.getcwd() @@ -52,7 +67,7 @@ def get_base_dir() -> str: return check_dir(os.path.join(cwd, "commands")) else: print("could not find working directory for Praxis_Bot/commands") - raise + raise Exception def get_implementations_dir() -> str: diff --git a/discord_script.py b/discord_script.py index 0515592..afa0783 100644 --- a/discord_script.py +++ b/discord_script.py @@ -28,7 +28,7 @@ class Discord_Module(discord.Client): self.cooldownModule:Cooldown_Module = Cooldown_Module() self.cooldownModule.setupCooldown("discordRateLimit", 10, 1) - self.commands = command_loader.load_commands() + self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.DISCORD) self.tts_enabled: bool = False diff --git a/twitch_script.py b/twitch_script.py index 8913582..ef530ae 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -23,7 +23,7 @@ class Twitch_Module(): self.db_manager: db.db_module = db.db_module() self.chat: twitch.Chat - self.commands = command_loader.load_commands() + self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.TWITCH) self.tts_enabled: bool = False self.tts_whitelist_enabled: bool = False self.links_allowed: bool = True