From 5bef8f754059e276dcb8531d58a2a39c6d5a94c2 Mon Sep 17 00:00:00 2001 From: ds Date: Mon, 31 Aug 2020 14:30:09 +0300 Subject: [PATCH] made help command to work properly. --- src/control.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/control.cpp b/src/control.cpp index 85bae71..e63771e 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -273,7 +273,8 @@ int BotControl::cmdNode () { "acquire_editor", "upload", "save", - "load" + "load", + "help" }; // check if cmd is allowed on dedicated server @@ -1606,16 +1607,32 @@ bool BotControl::executeCommands () { // give some help if (hasArg (1) && m_args[1] == "help") { - for (auto &item : m_cmds) { - if (aliasMatch (item.name, m_args[2], cmd)) { - msg ("Command: \"%s %s\"\nFormat: %s\nHelp: %s", prefix, cmd, item.format, conf.translate (item.help)); - msg ("Aliases: %s", String::join (item.name.split ("/"), ", ")); + const auto hasSecondArg = hasArg (2); - return true; + for (auto &item : m_cmds) { + if (!hasSecondArg) { + cmd = item.name.split ("/")[0]; + } + + if ((hasSecondArg && aliasMatch (item.name, m_args[2], cmd)) || !hasSecondArg) { + msg ("Command: \"%s %s\"\nFormat: %s\nHelp: %s", prefix, cmd, item.format, conf.translate (item.help)); + + auto aliases = item.name.split ("/"); + + if (aliases.length () > 1) { + msg ("Aliases: %s", String::join (aliases, ", ")); + } + + if (hasSecondArg) { + return true; + } + else { + msg ("\n"); + } } } - if (m_args[2].empty ()) { + if (!hasSecondArg) { return true; } else {