2018-02-23 22:05:40 +00:00
|
|
|
from os import listdir
|
2019-01-26 18:58:21 +00:00
|
|
|
|
2019-08-15 20:20:49 +00:00
|
|
|
from utils.logging.debug import debug
|
2019-08-25 20:29:11 +00:00
|
|
|
from utils.logging.log import *
|
2018-02-23 22:05:40 +00:00
|
|
|
import commands
|
|
|
|
|
2019-01-26 18:58:21 +00:00
|
|
|
from main import CommandMap
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-11-01 03:38:47 +00:00
|
|
|
def loadCommands(allowDup=False):
|
2019-03-16 17:05:16 +00:00
|
|
|
for filename in listdir("commands"):
|
|
|
|
if filename.endswith(".py") and filename != "__init__.py":
|
2018-02-23 22:05:40 +00:00
|
|
|
commandName = filename[0:-3]
|
2022-07-21 12:39:41 +00:00
|
|
|
className = commandName.capitalize() + "Command"
|
2018-02-23 23:26:21 +00:00
|
|
|
try:
|
2022-07-21 12:39:41 +00:00
|
|
|
module = __import__("commands.%s" % commandName)
|
2019-01-26 18:58:21 +00:00
|
|
|
if not commandName in CommandMap:
|
|
|
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
|
|
|
debug("Registered command: %s" % commandName)
|
|
|
|
else:
|
2020-11-01 03:38:47 +00:00
|
|
|
if allowDup:
|
|
|
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
|
|
|
debug("Registered command: %s" % commandName)
|
|
|
|
|
2019-01-26 18:58:21 +00:00
|
|
|
error("Duplicate command: %s" % (commandName))
|
2018-02-23 23:26:21 +00:00
|
|
|
except Exception as err:
|
|
|
|
error("Exception while loading command %s:\n%s" % (commandName, err))
|