]> jfr.im git - erebus.git/commitdiff
added help to each module
authorzonidjan <redacted>
Sat, 20 May 2017 21:20:44 +0000 (16:20 -0500)
committerzonidjan <redacted>
Sat, 20 May 2017 21:20:44 +0000 (16:20 -0500)
modules/control.py
modules/eval.py
modules/help.py
modules/resources.py
modules/sms.py
modules/trivia.py
modules/userinfo.py

index 5c95b0b6cad5f8ab0e6aad491ea1df73cf0ad2b0..cfc4ce643e837bde1ef52b787bfa49f56807c932 100644 (file)
@@ -23,6 +23,7 @@ from collections import deque
 
 
 @lib.hook(('die','restart'), needchan=False, glevel=lib.MANAGER)
+@lib.help(None, "stops the bot")
 def die(bot, user, chan, realtarget, *args):
        for botitem in bot.parent.bots.itervalues():
                for chan in botitem.chans:
@@ -32,6 +33,7 @@ def die(bot, user, chan, realtarget, *args):
        os._exit(0)
 
 @lib.hook(needchan=False, glevel=lib.MANAGER)
+@lib.help("<mod>", "loads a module")
 @lib.argsEQ(1)
 def modload(bot, user, chan, realtarget, *args):
        okay = ctlmod.load(bot.parent, args[0])
@@ -41,6 +43,7 @@ def modload(bot, user, chan, realtarget, *args):
                bot.msg(user, "Error loading %s: %r" % (args[0], okay))
 
 @lib.hook(needchan=False, glevel=lib.MANAGER)
+@lib.help("<mod>", "unloads a module")
 @lib.argsEQ(1)
 def modunload(bot, user, chan, realtarget, *args):
        okay = ctlmod.unload(bot.parent, args[0])
@@ -50,6 +53,7 @@ def modunload(bot, user, chan, realtarget, *args):
                bot.msg(user, "Error unloading %s: %r" % (args[0], okay))
 
 @lib.hook(needchan=False, glevel=lib.MANAGER)
+@lib.help("<mod>", "reloads a module")
 @lib.argsEQ(1)
 def modreload(bot, user, chan, realtarget, *args):
        okay = ctlmod.reloadmod(bot.parent, args[0])
@@ -59,6 +63,7 @@ def modreload(bot, user, chan, realtarget, *args):
                bot.msg(user, "Error occurred: %r" % (okay))
 
 @lib.hook(needchan=False, glevel=lib.STAFF)
+@lib.help(None, "list loaded modules")
 @lib.argsEQ(0)
 def modlist(bot, user, chan, realtarget, *args):
        mods = ctlmod.modules
@@ -90,6 +95,7 @@ def _whois(user, chan, showglevel=True, showclevel=True):
        return fmt % fillers
 
 @lib.hook(needchan=False)
+@lib.help("<user>", "shows who someone is")
 @lib.argsEQ(1)
 def whois(bot, user, chan, realtarget, *args):
        target = bot.parent.user(args[0], create=False)
@@ -99,14 +105,17 @@ def whois(bot, user, chan, realtarget, *args):
                bot.msg(user, "%s is %s" % (args[0], _whois(target, chan, (user.glevel >= 1), (chan is not None and chan.levelof(user.auth) >= 1))))
 
 @lib.hook(needchan=False)
+@lib.help(None, "shows who you are")
 def whoami(bot, user, chan, realtarget, *args):
        bot.msg(user, "You are %s" % (_whois(user, chan)))
 
 @lib.hook(needchan=False, glevel=1)
+@lib.help(None, "displays length of each msgqueue")
 def qstat(bot, user, chan, realtarget, *args):
        bot.fastmsg(user, "Regular: %d -- Slow: %d" % (len(bot.msgqueue), len(bot.slowmsgqueue)))
 
 @lib.hook(needchan=False, glevel=lib.ADMIN)
+@lib.help("[regular|slow]", "clears both or a specific msgqueue")
 def qclear(bot, user, chan, realtarget, *args):
        if len(args) == 0:
                bot.msgqueue = deque()
index 30eff66fc234c9c182a23ec0b31d6d836d89abd3..96b80c737fb6d3ba09143bf3945b4e8ed8c61ce7 100644 (file)
@@ -25,6 +25,7 @@ def module(name):
        return lib.mod(name)
 
 @lib.hook('eval', needchan=False, glevel=lib.MANAGER)
+@lib.help("<python>", "eval")
 @lib.argsGE(1)
 def cmd_eval(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
@@ -36,6 +37,7 @@ def cmd_eval(bot, user, chan, realtarget, *args):
 
 
 @lib.hook('exec', needchan=False, glevel=lib.MANAGER)
+@lib.help("<python>", "exec")
 @lib.argsGE(1)
 def cmd_exec(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
@@ -46,5 +48,6 @@ def cmd_exec(bot, user, chan, realtarget, *args):
        else: bot.msg(replyto, "Done.")
 
 @lib.hook('exception', glevel=lib.OWNER)
+@lib.help(None, "cause an exception")
 def cmd_exception(*args, **kwargs):
        raise Exception()
index 85588b00e40f663e17edc83465cbceb45e726355..bc4c17d39203886feb00ba70ef868331fb00dcc9 100644 (file)
@@ -58,8 +58,8 @@ def dereghelp(func, *args, **kwargs):
 
 @lib.hook(needchan=False)
 @lib.help('[<command>]', 'lists commands or describes a command')
-def help(bot, user, chan, realtarget, *args):
-       if len(args) == 0:
+def help(bot, user, chan, realtarget, *args): #TODO add ordering - by access level, then alphabetic?
+       if len(args) == 0: # list commands
                for func in helps.itervalues():
                        if user.glevel >= func.reqglevel:
                                if func.reqglevel <= 0:
@@ -69,7 +69,7 @@ def help(bot, user, chan, realtarget, *args):
                                if len(func.cmd) > 1:
                                        for c in func.cmd[1:]:
                                                bot.slowmsg(user, "%-40s - Alias of %s" % (c, func.cmd[0]))
-       else:
+       else: # help for a specific command/topic
                cmd = str(' '.join(args))
                if cmd in cmds and user.glevel >= cmds[cmd].reqglevel:
                        func = cmds[cmd]
index 520f762fb2b71e41b47672b344f9817aa278b52d..35feebda569f3e5e64c9e1c1d6eed1947bf2cf08 100644 (file)
@@ -20,6 +20,7 @@ modstop = lib.modstop
 import resource
 
 @lib.hook(needchan=False, glevel=lib.MANAGER)
+@lib.help(None, "show RAM usage")
 def ram(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
@@ -32,6 +33,7 @@ def ram(bot, user, chan, realtarget, *args):
        bot.fastmsg(replyto, "Memory usage (MiB): %r" % (res.ru_maxrss/1024.0))
 
 @lib.hook(needchan=False, glevel=lib.MANAGER)
+@lib.help(None, "show resource usage")
 def resources(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
index acf46dae365c8d6bc89a3c7556f830f32a4d91c3..80f5fb922449aa0753d79469b0f24951026757a7 100644 (file)
@@ -28,9 +28,10 @@ def client(bot):
 
 #@lib.hook(needchan=False, glevel=lib.MANAGER)
 def reply(bot, user, chan, realtarget, *args):
-       pass
+       return NotImplemented
 
 @lib.hook(('sms','w'), needchan=False, glevel=lib.OWNER)
+@lib.help("<number> <message>", "send an SMS")
 def sms(bot, user, chan, realtarget, *args):
        number = "+%s" % (args[0])
        message = ' '.join(args[1:])
index 3e2b093f481aaeb15f7a26eae1bd588c3ba46b4f..b9cd9f86eed95be27d8558dad20a4fa8251fb74b 100644 (file)
@@ -385,6 +385,7 @@ def trivia_checkanswer(bot, user, chan, *args):
                state.nextquestion()
 
 @lib.hook(needchan=False)
+@lib.help("[<user>]", "shows how many points you or someone has")
 def points(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
@@ -395,6 +396,7 @@ def points(bot, user, chan, realtarget, *args):
        bot.msg(replyto, "%s has %d points." % (who, state.points(who)))
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("<user> [<amount>]", "gives someone points", "defaults to 1 point")
 @lib.argsGE(1)
 def give(bot, user, chan, realtarget, *args):
        whoto = args[0]
@@ -407,6 +409,8 @@ def give(bot, user, chan, realtarget, *args):
        bot.msg(chan, "%s gave %s %d points. New balance: %d" % (user, whoto, numpoints, balance))
 
 @lib.hook(glevel=1, needchan=False)
+@lib.help("<qid>", "sets next question to one in the database")
+@lib.argsEQ(1)
 def setnextid(bot, user, chan, realtarget, *args):
        try:
                qid = int(args[0])
@@ -420,6 +424,7 @@ def setnextid(bot, user, chan, realtarget, *args):
                bot.msg(user, "Error: %s" % (e))
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("<q>*<a>", "sets next question to one not in database")
 @lib.argsGE(1)
 def setnext(bot, user, chan, realtarget, *args):
        line = ' '.join([str(arg) for arg in args])
@@ -433,10 +438,12 @@ def setnext(bot, user, chan, realtarget, *args):
        bot.msg(user, "Done.")
 
 @lib.hook(glevel=1, needchan=False)
+@lib.help(None, "skips to next question")
 def skip(bot, user, chan, realtarget, *args):
        state.nextquestion(qskipped=True, skipwait=True)
 
 @lib.hook(needchan=False)
+@lib.help(None, "starts the trivia game")
 def start(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
@@ -454,6 +461,7 @@ def start(bot, user, chan, realtarget, *args):
                bot.msg(user, "Game is already started!")
 
 @lib.hook('stop', glevel=1, needchan=False)
+@lib.help(None, "stops the trivia game")
 def cmd_stop(bot, user, chan, realtarget, *args):
        if stop():
                bot.msg(state.chan, "Game stopped by %s" % (user))
@@ -476,6 +484,7 @@ def stop():
        return True
 
 @lib.hook(needchan=False)
+@lib.help("<reason>", "reports a bad question to the admins")
 @lib.argsGE(1)
 def badq(bot, user, chan, realtarget, *args):
        lastqid = state.lastqid
@@ -487,6 +496,7 @@ def badq(bot, user, chan, realtarget, *args):
        bot.msg(user, "Reported bad question.")
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help(None, "shows a list of BADQ reports")
 def badqs(bot, user, chan, realtarget, *args):
        if len(state.db['badqs']) == 0:
                bot.msg(user, "No reports.")
@@ -505,12 +515,14 @@ def badqs(bot, user, chan, realtarget, *args):
                        bot.msg(user, "- Exception: %r" % (e))
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.hook(None, "clears list of BADQ reports")
 def clearbadqs(bot, user, chan, realtarget, *args):
        state.db['badqs'] = []
        state.savedb()
        bot.msg(user, "Cleared reports.")
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.hook("<badqid>", "removes a BADQ report")
 @lib.argsEQ(1)
 def delbadq(bot, user, chan, realtarget, *args):
        try:
@@ -522,6 +534,7 @@ def delbadq(bot, user, chan, realtarget, *args):
                bot.msg(user, "Failed!")
 
 @lib.hook(needchan=False)
+@lib.help("[<user>]", "shows you or someone else's rank")
 def rank(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
@@ -532,6 +545,7 @@ def rank(bot, user, chan, realtarget, *args):
        bot.msg(replyto, "%s is in %d place (%s points). Target is: %s (%s points)." % (who, state.rank(who), state.points(who), state.targetuser(who), state.targetpoints(who)))
 
 @lib.hook(needchan=False)
+@lib.help(None, "shows top10 list")
 def top10(bot, user, chan, realtarget, *args):
        if len(state.db['ranks']) == 0:
                return bot.msg(state.db['chan'], "No one is ranked!")
@@ -543,6 +557,7 @@ def top10(bot, user, chan, realtarget, *args):
        bot.msg(state.db['chan'], "Top 10: %s" % (replylist))
 
 @lib.hook(glevel=lib.ADMIN, needchan=False)
+@lib.help("<target score>", "changes the target score for this round")
 def settarget(bot, user, chan, realtarget, *args):
        try:
                state.db['target'] = int(args[0])
@@ -557,6 +572,7 @@ def settarget(bot, user, chan, realtarget, *args):
                bot.msg(user, "Failed to set target.")
 
 @lib.hook(needchan=False)
+@lib.help("<option>", "votes for a trarget score for next round")
 def vote(bot, user, chan, realtarget, *args):
        if state.pointvote is not None:
                if int(args[0]) in state.voteamounts:
@@ -568,6 +584,7 @@ def vote(bot, user, chan, realtarget, *args):
                bot.msg(user, "There's no vote in progress.")
 
 @lib.hook(glevel=lib.ADMIN, needchan=False)
+@lib.help("<number>", "sets the max missed question before game stops")
 def maxmissed(bot, user, chan, realtarget, *args):
        try:
                state.db['maxmissedquestions'] = int(args[0])
@@ -576,6 +593,7 @@ def maxmissed(bot, user, chan, realtarget, *args):
                bot.msg(user, "Failed to set maxmissed.")
 
 @lib.hook(glevel=lib.ADMIN, needchan=False)
+@lib.help("<seconds>", "sets the time between hints")
 def hinttimer(bot, user, chan, realtarget, *args):
        try:
                state.db['hinttimer'] = float(args[0])
@@ -584,6 +602,7 @@ def hinttimer(bot, user, chan, realtarget, *args):
                bot.msg(user, "Failed to set hint timer.")
 
 @lib.hook(glevel=lib.ADMIN, needchan=False)
+@lib.help("<number>", "sets the number of hints given")
 def hintnum(bot, user, chan, realtarget, *args):
        try:
                state.db['hintnum'] = int(args[0])
@@ -592,6 +611,7 @@ def hintnum(bot, user, chan, realtarget, *args):
                bot.msg(user, "Failed to set hintnum.")
 
 @lib.hook(glevel=lib.ADMIN, needchan=False)
+@lib.help("<seconds>", "sets the pause between questions")
 def questionpause(bot, user, chan, realtarget, *args):
        try:
                state.db['questionpause'] = float(args[0])
@@ -600,6 +620,7 @@ def questionpause(bot, user, chan, realtarget, *args):
                bot.msg(user, "Failed to set questionpause.")
 
 @lib.hook(glevel=1, needchan=False)
+@lib.help("<full question>", "finds a qid given a complete question")
 def findq(bot, user, chan, realtarget, *args):
        if len(args) == 0:
                bot.msg(user, "You need to specify the question.")
@@ -615,6 +636,7 @@ def findq(bot, user, chan, realtarget, *args):
                bot.msg(user, "No match.")
 
 @lib.hook(glevel=1, needchan=False)
+@lib.help("<regex>", "finds a qid given a regex or partial question")
 def findqre(bot, user, chan, realtarget, *args):
        if len(args) == 0:
                bot.msg(user, "You need to specify a search string.")
@@ -632,6 +654,7 @@ def findqre(bot, user, chan, realtarget, *args):
                bot.msg(user, "No match.")
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("<qid>", "displays the q*a for a qid")
 def showq(bot, user, chan, realtarget, *args):
        try:
                qid = int(args[0])
@@ -646,6 +669,7 @@ def showq(bot, user, chan, realtarget, *args):
        bot.msg(user, "%s: %s*%s" % (qid, q[0], q[1]))
 
 @lib.hook(('delq', 'deleteq'), glevel=lib.STAFF, needchan=False)
+@lib.help("<qid>", "removes a question from the database")
 def delq(bot, user, chan, realtarget, *args):
        try:
                backup = state.db['questions'][int(args[0])]
@@ -656,6 +680,7 @@ def delq(bot, user, chan, realtarget, *args):
                bot.msg(user, "Couldn't delete that question. %r" % (e))
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("<q>*<a>", "adds a question")
 def addq(bot, user, chan, realtarget, *args):
        line = ' '.join([str(arg) for arg in args])
        linepieces = line.split('*')
index 8cb8dfa43ec0e35b2366710d4902a9995b43b87e..33cbc0c7b2f5b81a60b64a01ec065b0eb50b0017 100644 (file)
@@ -70,6 +70,8 @@ def _set(user, key, value):
 
 #commands
 @lib.hook(needchan=False)
+@lib.help("[<user>] <item>", "gets an info item about you or someone else")
+@lib.argsGE(1)
 def getinfo(bot, user, chan, realtarget, *args):
        if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
@@ -88,12 +90,14 @@ def getinfo(bot, user, chan, realtarget, *args):
                bot.msg(replyto, "%(user)s: %(item)s on %(target)s: %(value)s" % {'user':user,'item':item,'target':target,'value':value})
 
 @lib.hook(needchan=False)
+@lib.help("<item> <value>", "sets an info item about you")
 @lib.argsGE(2)
 def setinfo(bot, user, chan, realtarget, *args):
        _set(user, args[0], ' '.join(args[1:]))
        bot.msg(user, "Done.")
 
 @lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("<user> <item> <value>", "sets an info item about someone else")
 @lib.argsGE(3)
 def osetinfo(bot, user, chan, realtarget, *args):
        _set(args[0], args[1], ' '.join(args[2:]))