Help is working
This commit is contained in:
@@ -104,9 +104,9 @@ class Commands(Thread):
|
||||
|
||||
def list_modules(self):
|
||||
success = True
|
||||
ret = ""
|
||||
ret = "List of modules:\n"
|
||||
for module in self.cmods.keys():
|
||||
ret = ret + module + "\n"
|
||||
ret = ret + " " + module + "\n"
|
||||
return success, ret.strip()
|
||||
|
||||
def _execute_command(self, method: str, *args, **kwargs) -> tuple:
|
||||
@@ -156,14 +156,17 @@ class Commands(Thread):
|
||||
success = False
|
||||
|
||||
if module == "":
|
||||
module = self.config["default"]
|
||||
if method == 'help':
|
||||
return self.list_modules()
|
||||
else:
|
||||
module = self.defmod
|
||||
|
||||
if not (module in self.cmods.keys()):
|
||||
m = module.replace("_", "-")
|
||||
if not (m in self.cmods.keys()):
|
||||
ret = 'module "{}" not found'.format(module)
|
||||
self.log.error(ret)
|
||||
return success, ret
|
||||
return success, (AEErrs.INVALID_REQUEST.value, ret)
|
||||
|
||||
return self.cmods[module]._execute_command(method, *args, **kwargs)
|
||||
|
||||
@@ -177,12 +180,12 @@ class Commands(Thread):
|
||||
|
||||
if len(args) == 0:
|
||||
cmds = inspect.getmembers(self, predicate=inspect.ismethod)
|
||||
cmds = [x for x in cmds if x[0].startswith("cmd_")]
|
||||
cmds = [x for x in cmds if x[0].startswith(self.precmd)]
|
||||
for m in cmds:
|
||||
ret = ret + m[0][len("cmd_") :] + "\n"
|
||||
ret = ret + m[0][len(self.precmd):] + "\n"
|
||||
else:
|
||||
if isinstance(args[0], str):
|
||||
cmd = "cmd_" + args[0]
|
||||
cmd = self.precmd + args[0]
|
||||
c = getattr(self, cmd, None)
|
||||
if c:
|
||||
r = inspect.getdoc(c)
|
||||
@@ -227,7 +230,7 @@ class CommandsLoader:
|
||||
if not obj is None:
|
||||
nmod = obj.nickname
|
||||
if nmod is None:
|
||||
nmod = (entry.name[:-3])[5:]
|
||||
nmod = (entry.name[:-3])[len(self.precmds):]
|
||||
cmds.update({nmod: obj})
|
||||
self.log.info('module "{}" loaded'.format(nmod))
|
||||
else:
|
||||
@@ -242,8 +245,8 @@ class CommandsLoader:
|
||||
module = import_module(name)
|
||||
members = inspect.getmembers(module, inspect.isclass)
|
||||
conf = None
|
||||
if name[5:] in self.config.sections():
|
||||
conf = self.config[name[5:]]
|
||||
if name[len(self.precmds):] in self.config.sections():
|
||||
conf = self.config[name[len(self.precmds):]]
|
||||
|
||||
obj = None
|
||||
for n, c in members:
|
||||
|
||||
Reference in New Issue
Block a user