You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
7 years ago
|
from os import listdir
|
||
6 years ago
|
|
||
2 years ago
|
from main import CommandMap
|
||
2 years ago
|
from utils.logging.debug import debug
|
||
2 years ago
|
from utils.logging.log import error
|
||
2 years ago
|
|
||
2 years ago
|
|
||
4 years ago
|
def loadCommands(allowDup=False):
|
||
6 years ago
|
for filename in listdir("commands"):
|
||
|
if filename.endswith(".py") and filename != "__init__.py":
|
||
7 years ago
|
commandName = filename[0:-3]
|
||
2 years ago
|
className = commandName.capitalize() + "Command"
|
||
2 years ago
|
# try:
|
||
|
module = __import__("commands.%s" % commandName)
|
||
2 years ago
|
if commandName not in CommandMap:
|
||
2 years ago
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
||
|
debug("Registered command: %s" % commandName)
|
||
|
else:
|
||
|
if allowDup:
|
||
2 years ago
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
||
6 years ago
|
debug("Registered command: %s" % commandName)
|
||
4 years ago
|
|
||
2 years ago
|
error("Duplicate command: %s" % (commandName))
|
||
|
# except Exception as err:
|
||
|
# error("Exception while loading command %s:\n%s" % (commandName, err))
|