From: zonidjan Date: Thu, 5 Oct 2017 02:16:48 +0000 (-0500) Subject: module cleanup X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/f5aec86546a7762dd0202f3983de22fe1c3814e9?ds=sidebyside module cleanup --- diff --git a/modules/chanops.py b/modules/chanops.py index 7d8f40c..bf73449 100644 --- a/modules/chanops.py +++ b/modules/chanops.py @@ -1,12 +1,12 @@ # Erebus IRC bot - Author: Erebus Team -# !EVAL and !EXEC commands +# chanop commands # This file is released into the public domain; see http://unlicense.org/ # module info modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': ['help'], } diff --git a/modules/coins.py b/modules/coins.py index 5b3d663..b489821 100644 --- a/modules/coins.py +++ b/modules/coins.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': [], } diff --git a/modules/control.py b/modules/control.py index c4caaf3..e00d013 100644 --- a/modules/control.py +++ b/modules/control.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': ['help'], } diff --git a/modules/eval.py b/modules/eval.py index d2b82c8..0ebb5ac 100644 --- a/modules/eval.py +++ b/modules/eval.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': ['help'], } @@ -25,11 +25,11 @@ import ctlmod def module(name): return lib.mod(name) -@lib.hook('eval', needchan=False, glevel=lib.MANAGER) +@lib.hook('eval', needchan=False, wantchan=True, glevel=lib.MANAGER) @lib.help("", "eval") @lib.argsGE(1) def cmd_eval(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + if chan is not None: replyto = chan else: replyto = user try: ret = eval(' '.join(args)) @@ -37,11 +37,11 @@ def cmd_eval(bot, user, chan, realtarget, *args): else: bot.msg(replyto, "Done: %r" % (ret,)) -@lib.hook('exec', needchan=False, glevel=lib.MANAGER) +@lib.hook('exec', needchan=False, wantchan=True, glevel=lib.MANAGER) @lib.help("", "exec") @lib.argsGE(1) def cmd_exec(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + if chan is not None: replyto = chan else: replyto = user try: exec ' '.join(args) diff --git a/modules/foo.py b/modules/foo.py index bb56be0..54e1b51 100644 --- a/modules/foo.py +++ b/modules/foo.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], # compatible module API versions + 'compatible': [2], # compatible module API versions 'depends': [], # other modules required to work properly? 'softdeps': ['help'], # modules which are preferred but not required } @@ -23,10 +23,10 @@ modstart = lib.modstart modstop = lib.modstop # module code -@lib.hook(needchan=False) #since no cmd= is provided, defaults to function name +@lib.hook(needchan=False, wantchan=True) #since no cmd= is provided, defaults to function name @lib.help('', 'tells you what you said') def test(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + if chan is not None: replyto = chan else: replyto = user bot.msg(replyto, "You said: %s" % (' '.join([str(arg) for arg in args]))) @@ -40,3 +40,10 @@ def foobar(bot, user, chan, realtarget, *args): @lib.help(None, 'a command that does nothing but requires you specify a channel') def needchan(bot, user, chan, realtarget, *args): bot.msg(user, "You did it!") + +@lib.hook(needchan=False, wantchan=True) +@lib.help(None, 'a command which will consume a channel if given') + if chan is not None: + bot.msg(user, "Channel provided: %s" % (chan)) + else: + bot.msg(user, "No channel provided") diff --git a/modules/help.py b/modules/help.py index 63541f8..27c80b7 100644 --- a/modules/help.py +++ b/modules/help.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': [], } diff --git a/modules/msg.py b/modules/msg.py index 1df017c..4e3b23f 100644 --- a/modules/msg.py +++ b/modules/msg.py @@ -5,7 +5,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': ['help'], } diff --git a/modules/resources.py b/modules/resources.py index 016e4bd..dacda23 100644 --- a/modules/resources.py +++ b/modules/resources.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': ['help'], } @@ -20,10 +20,10 @@ modstop = lib.modstop # module code import resource -@lib.hook(needchan=False, glevel=lib.MANAGER) +@lib.hook(needchan=False, wantchan=True, 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 + if chan is not None: replyto = chan else: replyto = user try: @@ -33,10 +33,10 @@ 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.hook(needchan=False, wantchan=True, 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 + if chan is not None: replyto = chan else: replyto = user try: diff --git a/modules/sms.py b/modules/sms.py index 16077a3..e388448 100644 --- a/modules/sms.py +++ b/modules/sms.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': ['help'], } diff --git a/modules/trivia.py b/modules/trivia.py index cba7a72..63143f4 100644 --- a/modules/trivia.py +++ b/modules/trivia.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': ['userinfo'], 'softdeps': ['help'], } @@ -411,10 +411,10 @@ def trivia_checkanswer(bot, user, chan, *args): bot.msg(chan, "\00312%s\003 got an extra point for getting it before the hints! New score: %d." % (user, state.addpoint(user))) state.nextquestion() -@lib.hook(glevel=1, needchan=False) +@lib.hook(glevel=1, needchan=False, wantchan=True) @lib.help(None, "saves the trivia database") def save(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + if chan is not None: replyto = chan else: replyto = user if state.savedb(): @@ -422,10 +422,10 @@ def save(bot, user, chan, realtarget, *args): else: bot.msg(replyto, "Save failed!") -@lib.hook(needchan=False) +@lib.hook(needchan=False, wantchan=True) @lib.help("[]", "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 + if chan is not None: eplyto = chan else: replyto = user if len(args) != 0: who = args[0] @@ -480,10 +480,10 @@ def setnext(bot, user, chan, realtarget, *args): def skip(bot, user, chan, realtarget, *args): state.nextquestion(qskipped=True, skipwait=True) -@lib.hook(needchan=False) +@lib.hook(needchan=False, wantchan=True) @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 + if chan is not None: replyto = chan else: replyto = user if chan is not None and chan.name != state.db['chan']: @@ -568,10 +568,10 @@ def delbadq(bot, user, chan, realtarget, *args): except: bot.msg(user, "Failed!") -@lib.hook(needchan=False) +@lib.hook(needchan=False, wantchan=True) @lib.help("[]", "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 + if chan is not None: replyto = chan else: replyto = user if len(args) != 0: who = args[0] diff --git a/modules/urls.py b/modules/urls.py index fc398e2..10e475b 100644 --- a/modules/urls.py +++ b/modules/urls.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': [], } diff --git a/modules/userinfo.py b/modules/userinfo.py index bd15053..03545a6 100644 --- a/modules/userinfo.py +++ b/modules/userinfo.py @@ -6,7 +6,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [2], 'depends': [], 'softdeps': ['help'], } @@ -72,10 +72,10 @@ def _set(user, key, value): db.setdefault(str(user).lower(), {})[key] = value #but set nick too #commands -@lib.hook(needchan=False) +@lib.hook(needchan=False, wantchan=True) @lib.help("[]", "lists info items known about someone", " may be a nick, or an auth in format '#auth'", "it defaults to yourself") def getitems(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + if chan is not None: replyto = chan else: replyto = user if len(args) > 0: @@ -85,11 +85,11 @@ def getitems(bot, user, chan, realtarget, *args): bot.msg(replyto, "%(user)s: %(target)s has the following info items: %(items)s" % {'user':user,'target':target,'items':(', '.join(_keys(target)))}) -@lib.hook(needchan=False) +@lib.hook(needchan=False, wantchan=True) @lib.help("[] ", "gets an info item about someone", " may be a nick, or an auth in format '#auth'", "it defaults to yourself") @lib.argsGE(1) def getinfo(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + if chan is not None: replyto = chan else: replyto = user if len(args) > 1: