2022-07-21 12:39:59 +00:00
|
|
|
from os import listdir
|
2022-07-21 12:40:01 +00:00
|
|
|
from importlib import reload
|
|
|
|
import sys
|
2019-01-26 18:58:21 +00:00
|
|
|
|
2022-07-21 12:39:59 +00:00
|
|
|
from utils.logging.debug import debug
|
|
|
|
from utils.logging.log import *
|
2022-07-21 12:40:01 +00:00
|
|
|
import commands
|
|
|
|
|
|
|
|
from main import CommandMap
|
2019-01-26 18:58:21 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-01-26 18:58:21 +00:00
|
|
|
def loadSingle(commandName):
|
2022-07-21 12:39:41 +00:00
|
|
|
if commandName + ".py" in listdir("commands"):
|
|
|
|
className = commandName.capitalize() + "Command"
|
2018-02-23 23:26:21 +00:00
|
|
|
try:
|
2019-01-26 18:58:21 +00:00
|
|
|
if commandName in CommandMap.keys():
|
2022-07-21 12:39:41 +00:00
|
|
|
reload(sys.modules["commands." + commandName])
|
2022-07-21 12:40:01 +00:00
|
|
|
CommandMap[commandName] = getattr(sys.modules["commands." + commandName], className)
|
2019-01-26 18:58:21 +00:00
|
|
|
debug("Reloaded command: %s" % commandName)
|
|
|
|
return "RELOAD"
|
2022-07-21 12:39:41 +00:00
|
|
|
module = __import__("commands.%s" % commandName)
|
2019-01-26 18:58:21 +00:00
|
|
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
|
|
|
debug("Registered command: %s" % commandName)
|
|
|
|
return True
|
|
|
|
|
2018-02-23 23:26:21 +00:00
|
|
|
except Exception as err:
|
|
|
|
return err
|
2019-01-26 18:58:21 +00:00
|
|
|
return False
|