From a048452debd2c26c874a55d4ff05286606938fb9 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Sun, 15 Mar 2009 01:25:32 -0600 Subject: [PATCH] simplifying interface (functions can now take one argument and return one string) --- bot.py | 6 +++++- plugins/bf.py | 4 ++-- plugins/dice.py | 6 +++--- plugins/hash.py | 12 ++++++------ plugins/pyexec.py | 4 ++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/bot.py b/bot.py index dc7f993..3416233 100755 --- a/bot.py +++ b/bot.py @@ -119,7 +119,11 @@ class FakeBot(object): self.say(self.input.nick + ': ' + msg) def run(self): - out = self.func(self, self.input) + ac = self.func.func_code.co_argcount + if ac == 2: + out = self.func(self, self.input) + elif ac == 1: + out = self.func(self.input.inp) if out is not None: if self.doreply: self.reply(unicode(out)) diff --git a/plugins/bf.py b/plugins/bf.py index 153ae3f..d921c9f 100644 --- a/plugins/bf.py +++ b/plugins/bf.py @@ -8,10 +8,10 @@ BUFFER_SIZE = 5000 MAX_STEPS = 1000000 #command -def bf(bot, input): +def bf(input): """Runs a Brainfuck program.""" - program = re.sub('[^][<>+-.,]', '', input.inp) + program = re.sub('[^][<>+-.,]', '', input) # create a dict of brackets pairs, for speed later on brackets={} diff --git a/plugins/dice.py b/plugins/dice.py index 560dd47..abbfcbe 100755 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -26,13 +26,13 @@ def nrolls(count, n): (((n+1)*(2*n+1)/6.-(.5*(1+n))**2)*count)**.5)) #command -def dice(bot, input): +def dice(input): ".dice - simulates dicerolls, e.g. .dice 2d20-d5+4 roll 2 " \ "D20s, subtract 1D5, add 4" - if not input.inp.strip(): + if not input.strip(): return dice.__doc__ - spec = whitespace_re.sub('', input.inp) + spec = whitespace_re.sub('', input) if not valid_diceroll_re.match(spec): return "Invalid diceroll" sum = 0 diff --git a/plugins/hash.py b/plugins/hash.py index 9b69126..a7916e5 100644 --- a/plugins/hash.py +++ b/plugins/hash.py @@ -1,14 +1,14 @@ import hashlib #command -def md5(bot, input): - return hashlib.md5(input.inp).hexdigest() +def md5(input): + return hashlib.md5(input).hexdigest() #command -def sha1(bot, input): - return hashlib.sha1(input.inp).hexdigest() +def sha1(input): + return hashlib.sha1(input).hexdigest() #command -def hash(bot, input): - return ', '.join(x + ": " + getattr(hashlib, x)(input.inp).hexdigest() +def hash(input): + return ', '.join(x + ": " + getattr(hashlib, x)(input).hexdigest() for x in 'md5 sha1 sha256'.split()) diff --git a/plugins/pyexec.py b/plugins/pyexec.py index f8e10d9..0280625 100644 --- a/plugins/pyexec.py +++ b/plugins/pyexec.py @@ -4,9 +4,9 @@ import re re_lineends = re.compile(r'[\r\n]*') #command -def py(bot, input): +def py(input): res = urllib.urlopen("http://eval.appspot.com/eval?statement=%s" % - urllib.quote(input.inp.strip(),safe='')).readlines() + urllib.quote(input.strip(),safe='')).readlines() if len(res) == 0: return res[0] = re_lineends.split(res[0])[0]