From 520c0aa2536041377f1c00976e01421c44b8712f Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 31 Dec 2021 00:51:43 +0000 Subject: [PATCH] Implement help for commands --- handler/commands.py | 19 +++++++++++++++++++ handler/irc.py | 21 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/handler/commands.py b/handler/commands.py index 64c4fa0..f18ed4d 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -6,6 +6,7 @@ class IRCCommands(object): class trades(object): name = "trades" authed = True + helptext = "Get all open trades." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -25,6 +26,7 @@ class IRCCommands(object): class create(object): name = "create" authed = True + helptext = "Create an ad. Usage: create " @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -40,6 +42,7 @@ class IRCCommands(object): class messages(object): name = "messages" authed = True + helptext = "Get messages. Usage: messages []" @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -73,6 +76,7 @@ class IRCCommands(object): class dist(object): name = "dist" authed = True + helptext = "Distribute all our chosen currency and country ad pairs." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -86,6 +90,7 @@ class IRCCommands(object): class brute(object): name = "brute" authed = True + helptext = "Use a bruteforce algorithm to create all possible currency and country pairs." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -98,6 +103,7 @@ class IRCCommands(object): class fillblanks(object): name = "fillblanks" authed = True + helptext = "Resume a run of brute by getting all our adverts then filling the blanks." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -110,6 +116,7 @@ class IRCCommands(object): class stripdupes(object): name = "stripdupes" authed = True + helptext = "Remove all duplicate adverts." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -119,6 +126,7 @@ class IRCCommands(object): class find(object): name = "find" authed = True + helptext = "Finx a transaction. Usage: find " @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -140,6 +148,7 @@ class IRCCommands(object): class accounts(object): name = "accounts" authed = True + helptext = "Get all account information from Revolut." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -161,6 +170,7 @@ class IRCCommands(object): class total(object): name = "total" authed = True + helptext = "Get total account balance from Revolut in USD." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -172,6 +182,7 @@ class IRCCommands(object): class ping(object): name = "ping" authed = False + helptext = "Pong!" @staticmethod def run(cmd, spl, length, authed, msg): @@ -180,6 +191,7 @@ class IRCCommands(object): class release_url(object): name = "release_url" authed = True + helptext = "Get release URL for all open trades." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -192,6 +204,7 @@ class IRCCommands(object): class message(object): name = "msg" authed = True + helptext = "Send a message on a trade. Usage: msg " @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -207,6 +220,7 @@ class IRCCommands(object): class refs(object): name = "refs" authed = True + helptext = "List all references" @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -215,6 +229,7 @@ class IRCCommands(object): class ref(object): name = "ref" authed = True + helptext = "Get more information about a reference. Usage: ref " @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -228,6 +243,7 @@ class IRCCommands(object): class delete(object): name = "del" authed = True + helptext = "Delete a reference. Usage: del " @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -242,6 +258,7 @@ class IRCCommands(object): class release(object): name = "release" authed = True + helptext = "Release funds for a trade. Usage: release " @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -256,6 +273,7 @@ class IRCCommands(object): class nuke(object): name = "nuke" authed = True + helptext = "Delete all our adverts." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): @@ -265,6 +283,7 @@ class IRCCommands(object): class wallet(object): name = "wallet" authed = True + helptext = "Get Agora wallet balance in XMR." @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): diff --git a/handler/irc.py b/handler/irc.py index 98d8080..2ac97d4 100644 --- a/handler/irc.py +++ b/handler/irc.py @@ -62,9 +62,28 @@ class IRCBot(irc.IRCClient): # nick = user.split("!")[0] cmd = spl[0] + length = len(spl) # Check if user is authenticated authed = host in self.admins + if cmd == "help" and length == 2 and authed: + if spl[1] in self.cmdhash: + cmdname = self.cmdhash[spl[1]] + obj = getattr(self.cmd, cmdname) + helptext = getattr(obj, "helptext") + self.msg(channel, helptext) + return + else: + self.msg(channel, f"No such command: {spl[1]}") + return + if cmd == "helpall" and authed: + for command in self.cmdhash: + cmdname = self.cmdhash[command] + obj = getattr(self.cmd, cmdname) + helptext = getattr(obj, "helptext") + self.msg(channel, f"{cmdname}: {helptext}") + return + if cmd in self.cmdhash: # Get the class name of the referenced command cmdname = self.cmdhash[cmd] @@ -77,7 +96,7 @@ class IRCBot(irc.IRCClient): # Check if the command required authentication if obj.authed: if host in self.admins: - obj.run(cmd, spl, len(spl), authed, msgl, self.agora, self.revolut, self.tx) + obj.run(cmd, spl, length, authed, msgl, self.agora, self.revolut, self.tx) else: # Handle authentication here instead of in the command module for security self.msg(channel, "Access denied.")