From 33585f3190c2f44c0dda9e6654015692c7013c19 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Sun, 17 Jan 2010 16:07:08 -0700 Subject: [PATCH] put input.inp.strip() in sieve, remove repetitive stripping in plugins --- plugins/dice.py | 2 +- plugins/down.py | 1 - plugins/explain.py | 2 +- plugins/help.py | 2 +- plugins/pyexec.py | 2 +- plugins/remember.py | 7 +++---- plugins/seen.py | 2 +- plugins/sieve.py | 3 ++- plugins/suggest.py | 5 +++-- plugins/tell.py | 2 +- plugins/twitter.py | 1 - plugins/urbandictionary.py | 4 ++-- plugins/weather.py | 2 +- plugins/wikipedia.py | 6 +++--- 14 files changed, 20 insertions(+), 21 deletions(-) diff --git a/plugins/dice.py b/plugins/dice.py index 13bb040..d4f6523 100644 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -33,7 +33,7 @@ def nrolls(count, n): def dice(inp): ".dice -- simulates dicerolls, e.g. .dice 2d20-d5+4 roll 2 " \ "D20s, subtract 1D5, add 4" - if not inp.strip(): + if not inp: return dice.__doc__ spec = whitespace_re.sub('', inp) diff --git a/plugins/down.py b/plugins/down.py index a6247d7..4842242 100644 --- a/plugins/down.py +++ b/plugins/down.py @@ -6,7 +6,6 @@ from util import hook @hook.command def down(inp): '''.down -- checks to see if the site is down''' - inp = inp.strip() if not inp: return down.__doc__ diff --git a/plugins/explain.py b/plugins/explain.py index ba24501..33b78a1 100755 --- a/plugins/explain.py +++ b/plugins/explain.py @@ -10,6 +10,6 @@ def explain(inp): inp = inp.encode('utf8', 'ignore') try: - return explain_c_declaration(inp.rstrip()) + return explain_c_declaration(inp) except Exception, e: return 'error: %s' % e diff --git a/plugins/help.py b/plugins/help.py index af73ce1..af55d2d 100644 --- a/plugins/help.py +++ b/plugins/help.py @@ -10,7 +10,7 @@ def help(bot, input): if func.__doc__ is not None: funcs[csig[1]] = func - if not input.inp.strip(): + if not input.inp: input.pm('available commands: ' + ' '.join(sorted(funcs))) else: if input.inp in funcs: diff --git a/plugins/pyexec.py b/plugins/pyexec.py index f6e3e78..3887779 100644 --- a/plugins/pyexec.py +++ b/plugins/pyexec.py @@ -15,7 +15,7 @@ def py(inp): return py.__doc__ res = urllib.urlopen("http://eval.appspot.com/eval?statement=%s" % - urllib.quote(inp.strip(), safe='')).readlines() + urllib.quote(inp, safe='')).readlines() if len(res) == 0: return res[0] = re_lineends.split(res[0])[0] diff --git a/plugins/remember.py b/plugins/remember.py index 4d2904e..e15e22b 100644 --- a/plugins/remember.py +++ b/plugins/remember.py @@ -46,14 +46,13 @@ def remember(bot, input): except ValueError: return remember.__doc__ - tail = tail.strip() low = head.lower() if low not in memory[filename]: input.reply("done.") else: input.reply('forgetting that "%s", remembering this instead.' % memory[filename][low]) - memory[filename][low] = input.inp.strip() + memory[filename][low] = input.inp save_memory(filename, memory[filename]) @@ -64,10 +63,10 @@ def forget(bot, input): filename = make_filename(bot.persist_dir, input.chan) memory.setdefault(filename, load_memory(filename)) - if not input.inp.strip(): + if not input.inp: return forget.__doc__ - low = input.inp.strip().lower() + low = input.inp.lower() if low not in memory[filename]: return "I don't know about that." if not hasattr(input, 'chan'): diff --git a/plugins/seen.py b/plugins/seen.py index 64308f5..72b29ef 100644 --- a/plugins/seen.py +++ b/plugins/seen.py @@ -40,7 +40,7 @@ def seen(bot, input): if len(input.msg) < 6: return seen.__doc__ - query = input.inp.strip() + query = input.inp if query.lower() == input.nick.lower(): return "Have you looked in a mirror lately?" diff --git a/plugins/sieve.py b/plugins/sieve.py index bb3fde3..197a040 100644 --- a/plugins/sieve.py +++ b/plugins/sieve.py @@ -24,6 +24,7 @@ def sieve_suite(bot, input, func, args): if input.re is None: return None - input.inp = ' '.join(input.re.groups()) + input.inp_unstripped = ' '.join(input.re.groups()) + input.inp = input.inp_unstripped.strip() return input diff --git a/plugins/suggest.py b/plugins/suggest.py index 55cbf12..c92c821 100644 --- a/plugins/suggest.py +++ b/plugins/suggest.py @@ -7,11 +7,12 @@ import json from util import hook @hook.command -def suggest(inp): +def suggest(bot, input): ".suggest [#n] -- gets a random/the nth suggested google search" - if not inp.strip(): + if not input.inp: return suggest.__doc__ + inp = input.inp_unstripped m = re.match('^#(\d+) (.+)$', inp) if m: num, inp = m.groups() diff --git a/plugins/tell.py b/plugins/tell.py index bdfc9ec..b2f1237 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -81,7 +81,7 @@ def tell(bot, input): if len(input.msg) < 6: return tell.__doc__ - query = input.msg[6:].strip().partition(" ") + query = input.inp.partition(" ") if query[0] == input.nick: return "No." diff --git a/plugins/twitter.py b/plugins/twitter.py index 245360f..239fc0f 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -31,7 +31,6 @@ def twitter(inp): ".twitter / //#/@ -- gets last/th tweet from"\ "/gets tweet /gets random tweet with #/gets replied tweet from @" - inp = inp.strip() if not inp: return twitter.__doc__ diff --git a/plugins/urbandictionary.py b/plugins/urbandictionary.py index 2327df6..7021a49 100644 --- a/plugins/urbandictionary.py +++ b/plugins/urbandictionary.py @@ -8,11 +8,11 @@ from util import hook @hook.command def urban(inp): '''.u/.urban -- looks up on urbandictionary.com''' - if not inp.strip(): + if not inp: return urban.__doc__ url = 'http://www.urbandictionary.com/define.php?term=' + \ - urllib.quote(inp.strip(), safe='') + urllib.quote(inp, safe='') page = html.parse(url) words = page.xpath("//td[@class='word']") defs = page.xpath("//div[@class='definition']") diff --git a/plugins/weather.py b/plugins/weather.py index 9556b9f..9068b8e 100644 --- a/plugins/weather.py +++ b/plugins/weather.py @@ -41,7 +41,7 @@ def weather(bot, input): stalk = load_stalk(filename) nick = input.nick.lower() - loc = input.inp.strip() + loc = input.inp dontsave = loc.endswith(" dontsave") if dontsave: loc = loc[:-9].strip().lower() diff --git a/plugins/wikipedia.py b/plugins/wikipedia.py index 8c560ec..93eaa87 100644 --- a/plugins/wikipedia.py +++ b/plugins/wikipedia.py @@ -16,14 +16,14 @@ paren_re = re.compile('\s*\(.*\)$') @hook.command(hook='w(\s+.*|$)') @hook.command -def wiki(query): +def wiki(inp): '''.w/.wiki -- gets first sentence of wikipedia ''' \ '''article on ''' - if not query.strip(): + if not inp: return wiki.__doc__ - q = search_url % (urllib.quote(query.strip(), safe='')) + q = search_url % (urllib.quote(inp, safe='')) x = etree.parse(q) ns = '{http://opensearch.org/searchsuggest2}'