Implement help for commands
This commit is contained in:
parent
5649909385
commit
520c0aa253
|
@ -6,6 +6,7 @@ class IRCCommands(object):
|
||||||
class trades(object):
|
class trades(object):
|
||||||
name = "trades"
|
name = "trades"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Get all open trades."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -25,6 +26,7 @@ class IRCCommands(object):
|
||||||
class create(object):
|
class create(object):
|
||||||
name = "create"
|
name = "create"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Create an ad. Usage: create <country> <currency>"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -40,6 +42,7 @@ class IRCCommands(object):
|
||||||
class messages(object):
|
class messages(object):
|
||||||
name = "messages"
|
name = "messages"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Get messages. Usage: messages [<reference>]"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -73,6 +76,7 @@ class IRCCommands(object):
|
||||||
class dist(object):
|
class dist(object):
|
||||||
name = "dist"
|
name = "dist"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Distribute all our chosen currency and country ad pairs."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -86,6 +90,7 @@ class IRCCommands(object):
|
||||||
class brute(object):
|
class brute(object):
|
||||||
name = "brute"
|
name = "brute"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Use a bruteforce algorithm to create all possible currency and country pairs."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -98,6 +103,7 @@ class IRCCommands(object):
|
||||||
class fillblanks(object):
|
class fillblanks(object):
|
||||||
name = "fillblanks"
|
name = "fillblanks"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Resume a run of brute by getting all our adverts then filling the blanks."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -110,6 +116,7 @@ class IRCCommands(object):
|
||||||
class stripdupes(object):
|
class stripdupes(object):
|
||||||
name = "stripdupes"
|
name = "stripdupes"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Remove all duplicate adverts."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -119,6 +126,7 @@ class IRCCommands(object):
|
||||||
class find(object):
|
class find(object):
|
||||||
name = "find"
|
name = "find"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Finx a transaction. Usage: find <currency> <amount>"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -140,6 +148,7 @@ class IRCCommands(object):
|
||||||
class accounts(object):
|
class accounts(object):
|
||||||
name = "accounts"
|
name = "accounts"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Get all account information from Revolut."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -161,6 +170,7 @@ class IRCCommands(object):
|
||||||
class total(object):
|
class total(object):
|
||||||
name = "total"
|
name = "total"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Get total account balance from Revolut in USD."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -172,6 +182,7 @@ class IRCCommands(object):
|
||||||
class ping(object):
|
class ping(object):
|
||||||
name = "ping"
|
name = "ping"
|
||||||
authed = False
|
authed = False
|
||||||
|
helptext = "Pong!"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg):
|
def run(cmd, spl, length, authed, msg):
|
||||||
|
@ -180,6 +191,7 @@ class IRCCommands(object):
|
||||||
class release_url(object):
|
class release_url(object):
|
||||||
name = "release_url"
|
name = "release_url"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Get release URL for all open trades."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -192,6 +204,7 @@ class IRCCommands(object):
|
||||||
class message(object):
|
class message(object):
|
||||||
name = "msg"
|
name = "msg"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Send a message on a trade. Usage: msg <reference> <message...>"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -207,6 +220,7 @@ class IRCCommands(object):
|
||||||
class refs(object):
|
class refs(object):
|
||||||
name = "refs"
|
name = "refs"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "List all references"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -215,6 +229,7 @@ class IRCCommands(object):
|
||||||
class ref(object):
|
class ref(object):
|
||||||
name = "ref"
|
name = "ref"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Get more information about a reference. Usage: ref <reference>"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -228,6 +243,7 @@ class IRCCommands(object):
|
||||||
class delete(object):
|
class delete(object):
|
||||||
name = "del"
|
name = "del"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Delete a reference. Usage: del <reference>"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -242,6 +258,7 @@ class IRCCommands(object):
|
||||||
class release(object):
|
class release(object):
|
||||||
name = "release"
|
name = "release"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Release funds for a trade. Usage: release <reference>"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -256,6 +273,7 @@ class IRCCommands(object):
|
||||||
class nuke(object):
|
class nuke(object):
|
||||||
name = "nuke"
|
name = "nuke"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Delete all our adverts."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
@ -265,6 +283,7 @@ class IRCCommands(object):
|
||||||
class wallet(object):
|
class wallet(object):
|
||||||
name = "wallet"
|
name = "wallet"
|
||||||
authed = True
|
authed = True
|
||||||
|
helptext = "Get Agora wallet balance in XMR."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
|
|
@ -62,9 +62,28 @@ class IRCBot(irc.IRCClient):
|
||||||
# nick = user.split("!")[0]
|
# nick = user.split("!")[0]
|
||||||
|
|
||||||
cmd = spl[0]
|
cmd = spl[0]
|
||||||
|
length = len(spl)
|
||||||
|
|
||||||
# Check if user is authenticated
|
# Check if user is authenticated
|
||||||
authed = host in self.admins
|
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:
|
if cmd in self.cmdhash:
|
||||||
# Get the class name of the referenced command
|
# Get the class name of the referenced command
|
||||||
cmdname = self.cmdhash[cmd]
|
cmdname = self.cmdhash[cmd]
|
||||||
|
@ -77,7 +96,7 @@ class IRCBot(irc.IRCClient):
|
||||||
# Check if the command required authentication
|
# Check if the command required authentication
|
||||||
if obj.authed:
|
if obj.authed:
|
||||||
if host in self.admins:
|
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:
|
else:
|
||||||
# Handle authentication here instead of in the command module for security
|
# Handle authentication here instead of in the command module for security
|
||||||
self.msg(channel, "Access denied.")
|
self.msg(channel, "Access denied.")
|
||||||
|
|
Loading…
Reference in New Issue