From 4a2b9efbe78d110fbab67550c6726da695e1368d Mon Sep 17 00:00:00 2001 From: "Sean B. Palmer" Date: Wed, 23 Feb 2011 21:32:37 +0000 Subject: Added reminders module. --- modules/calc.py | 4 +++- modules/head.py | 2 ++ modules/oblique.py | 6 +++--- modules/tell.py | 34 +++++++--------------------------- modules/wikipedia.py | 2 +- 5 files changed, 16 insertions(+), 32 deletions(-) diff --git a/modules/calc.py b/modules/calc.py index ab0f3fa..88ac814 100755 --- a/modules/calc.py +++ b/modules/calc.py @@ -78,6 +78,8 @@ def c(phenny, input): answer = [p for p in parts if p.startswith('rhs: "')][0][6:] if answer: answer = answer.decode('unicode-escape') + answer = ''.join(chr(ord(c)) for c in answer) + answer = answer.decode('utf-8') answer = answer.replace(u'\xc2\xa0', ',') answer = answer.replace('', '^(') answer = answer.replace('', ')') @@ -97,7 +99,7 @@ def py(phenny, input): py.commands = ['py'] def wa(phenny, input): - query = input.group(2) + query = input.group(2).encode('utf-8') uri = 'http://tumbolia.appspot.com/wa/' answer = web.get(uri + web.urllib.quote(query)) if answer: diff --git a/modules/head.py b/modules/head.py index 384b8df..1008628 100755 --- a/modules/head.py +++ b/modules/head.py @@ -26,6 +26,7 @@ def head(phenny, input): if not uri.startswith('htt'): uri = 'http://' + uri + # uri = uri.replace('#!', '?_escaped_fragment_=') try: info = web.head(uri) except IOError: return phenny.say("Can't connect to %s" % uri) @@ -80,6 +81,7 @@ def f_title(self, origin, match, args): if not ':' in uri: uri = 'http://' + uri + uri = uri.replace('#!', '?_escaped_fragment_=') try: redirects = 0 diff --git a/modules/oblique.py b/modules/oblique.py index 3622b4a..6d6156c 100755 --- a/modules/oblique.py +++ b/modules/oblique.py @@ -30,9 +30,9 @@ def mappings(uri): def service(phenny, input, command, args): t = o.services[command] - template = t.replace('${args}', urllib.quote(args.encode('utf-8'))) - template = template.replace('${nick}', urllib.quote(input.nick)) - uri = template.replace('${sender}', urllib.quote(input.sender)) + template = t.replace('${args}', urllib.quote(args.encode('utf-8'), '')) + template = template.replace('${nick}', urllib.quote(input.nick, '')) + uri = template.replace('${sender}', urllib.quote(input.sender, '')) info = web.head(uri) if isinstance(info, list): diff --git a/modules/tell.py b/modules/tell.py index 741c58d..5e61007 100755 --- a/modules/tell.py +++ b/modules/tell.py @@ -82,13 +82,13 @@ def f_remind(phenny, input): if not phenny.reminders.has_key(tellee): phenny.reminders[tellee] = [(teller, verb, timenow, msg)] else: - if len(phenny.reminders[tellee]) >= maximum: - warn = True + # if len(phenny.reminders[tellee]) >= maximum: + # warn = True phenny.reminders[tellee].append((teller, verb, timenow, msg)) # @@ Stephanie's augmentation response = "I'll pass that on when %s is around." % tellee_original - if warn: response += (" I'll have to use a pastebin, though, so " + - "your message may get lost.") + # if warn: response += (" I'll have to use a pastebin, though, so " + + # "your message may get lost.") rand = random.random() if rand > 0.9999: response = "yeah, yeah" @@ -138,29 +138,9 @@ def message(phenny, input): phenny.say(line) if reminders[maximum:]: - try: - if origin.sender in lispchannels: - chan = origin.sender - else: chan = 'None' - - result = web.post('http://paste.lisp.org/submit', - {'channel': chan, - 'username': phenny.nick, - 'title': 'Further Messages for %s' % tellee, - 'colorize': 'None', - 'text': '\n'.join(reminders[maximum:]) + '\n', - 'captcha': 'lisp', - 'captchaid': 'bdf447484f62a3e8b23816f9acee79d9' - } - ) - uris = re.findall('http://paste.lisp.org/display/\d+', result) - uri = list(reversed(uris)).pop() - if not origin.sender in lispchannels: - message = '%s: see %s for further messages' % (tellee, uri) - phenny.say(message) - except: - error = '[Sorry, some messages were elided and lost...]' - phenny.say(error) + phenny.say('Further messages sent privately') + for line in reminders[maximum:]: + phenny.msg(tellee, line) if len(phenny.reminders.keys()) != remkeys: dumpReminders(phenny.tell_filename, phenny.reminders) # @@ tell diff --git a/modules/wikipedia.py b/modules/wikipedia.py index 0542067..30a23f3 100755 --- a/modules/wikipedia.py +++ b/modules/wikipedia.py @@ -24,7 +24,7 @@ r_redirect = re.compile( abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs', 'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit', - 'syn', 'transl', 'sess', 'fl', 'Op'] \ + 'syn', 'transl', 'sess', 'fl', 'Op', 'Dec'] \ + list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \ + list('abcdefghijklmnopqrstuvwxyz') t_sentence = r'^.{5,}?(?