2
0
mirror of https://github.com/Nick80835/microbot synced 2025-09-01 06:55:51 +00:00

add a help command to list available commands

This commit is contained in:
Nick80835
2020-05-06 11:10:00 -04:00
parent 3751d7de9a
commit 5272c0c85e
2 changed files with 20 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ class Loader():
self.logger = logger
self.settings = settings
self.command_handler = CommandHandler(client, logger, settings)
self.help_dict = {}
self.botversion = "0.1.3"
def load_all_modules(self):
@@ -29,6 +30,7 @@ class Loader():
def reload_all_modules(self):
self.command_handler.incoming_commands = {}
self.help_dict = {}
errors = ""
@@ -47,6 +49,11 @@ class Loader():
pattern = args.get("pattern", pattern)
def decorator(func):
if func.__module__.split(".")[-1] in self.help_dict:
self.help_dict[func.__module__.split(".")[-1]] += [pattern]
else:
self.help_dict[func.__module__.split(".")[-1]] = [pattern]
self.command_handler.incoming_commands[pattern] = {
"function": func,
"noprefix": args.get('noprefix', False),

View File

@@ -32,6 +32,19 @@ async def delete_message(event):
await message_to_delete.delete()
@ldr.add("help")
async def help_cmd(event):
help_string = ""
for key, value in ldr.help_dict.items():
help_string += f"\n**{key}**: "
for info in value:
help_string += f"`{info}`, "
help_string = help_string.rstrip(", ")
await event.reply(f"`Available commands:`\n{help_string}")
@ldr.add("alive", sudo=True)
async def alive(event):
alive_format = "`μBot is running under {0}.\n\n" \