Moved files to subdirectory

This commit is contained in:
2022-09-06 12:50:09 +01:00
parent 2c3d83fe9a
commit bd9f9378cf
83 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
from os import listdir
from main import CommandMap
from utils.logging.debug import debug
from utils.logging.log import error
def loadCommands(allowDup=False):
for filename in listdir("commands"):
if filename.endswith(".py") and filename != "__init__.py":
commandName = filename[0:-3]
className = commandName.capitalize() + "Command"
# try:
module = __import__("commands.%s" % commandName)
if commandName not in CommandMap:
CommandMap[commandName] = getattr(getattr(module, commandName), className)
debug("Registered command: %s" % commandName)
else:
if allowDup:
CommandMap[commandName] = getattr(getattr(module, commandName), className)
debug("Registered command: %s" % commandName)
error("Duplicate command: %s" % (commandName))
# except Exception as err:
# error("Exception while loading command %s:\n%s" % (commandName, err))

View File

@@ -0,0 +1,25 @@
import sys
from importlib import reload
from os import listdir
from main import CommandMap
from utils.logging.debug import debug
def loadSingle(commandName):
if commandName + ".py" in listdir("commands"):
className = commandName.capitalize() + "Command"
try:
if commandName in CommandMap.keys():
reload(sys.modules["commands." + commandName])
CommandMap[commandName] = getattr(sys.modules["commands." + commandName], className)
debug("Reloaded command: %s" % commandName)
return "RELOAD"
module = __import__("commands.%s" % commandName)
CommandMap[commandName] = getattr(getattr(module, commandName), className)
debug("Registered command: %s" % commandName)
return True
except Exception as err:
return err
return False