simplifying interface (functions can now take one argument and return one string)

This commit is contained in:
Ryan Hitchman 2009-03-15 01:25:32 -06:00
parent ffc57460b1
commit a048452deb
5 changed files with 18 additions and 14 deletions

6
bot.py
View File

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

View File

@ -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={}

View File

@ -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 <diceroll> - 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

View File

@ -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())

View File

@ -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]