Implement help for commands

This commit is contained in:
Mark Veidemanis 2021-12-31 00:51:43 +00:00
parent 5649909385
commit 520c0aa253
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 39 additions and 1 deletions

View File

@ -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 <country> <currency>"
@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 [<reference>]"
@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 <currency> <amount>"
@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 <reference> <message...>"
@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 <reference>"
@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 <reference>"
@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 <reference>"
@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):

View File

@ -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.")