Updated Command Loader
This commit is contained in:
parent
0e0456ca9e
commit
a167a7eba4
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user