2018-02-23 22:05:40 +00:00
|
|
|
from os import listdir
|
2019-01-26 18:58:21 +00:00
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
from utils.logging.log import *
|
|
|
|
import commands
|
|
|
|
|
2019-01-26 18:58:21 +00:00
|
|
|
from main import CommandMap
|
|
|
|
|
|
|
|
def loadCommands():
|
2018-02-23 22:05:40 +00:00
|
|
|
for filename in listdir('commands'):
|
|
|
|
if filename.endswith('.py') and filename != "__init__.py":
|
|
|
|
commandName = filename[0:-3]
|
|
|
|
className = commandName.capitalize()
|
2018-02-23 23:26:21 +00:00
|
|
|
try:
|
2019-01-26 18:58:21 +00:00
|
|
|
module = __import__('commands.%s' % commandName)
|
|
|
|
if not commandName in CommandMap:
|
|
|
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
|
|
|
debug("Registered command: %s" % commandName)
|
|
|
|
else:
|
|
|
|
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))
|