Added reminders module.

master
Sean B. Palmer 2011-02-23 21:32:37 +00:00
parent 4608c57ea8
commit 4a2b9efbe7
5 changed files with 16 additions and 32 deletions

View File

@ -78,6 +78,8 @@ def c(phenny, input):
answer = [p for p in parts if p.startswith('rhs: "')][0][6:] answer = [p for p in parts if p.startswith('rhs: "')][0][6:]
if answer: if answer:
answer = answer.decode('unicode-escape') 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(u'\xc2\xa0', ',')
answer = answer.replace('<sup>', '^(') answer = answer.replace('<sup>', '^(')
answer = answer.replace('</sup>', ')') answer = answer.replace('</sup>', ')')
@ -97,7 +99,7 @@ def py(phenny, input):
py.commands = ['py'] py.commands = ['py']
def wa(phenny, input): def wa(phenny, input):
query = input.group(2) query = input.group(2).encode('utf-8')
uri = 'http://tumbolia.appspot.com/wa/' uri = 'http://tumbolia.appspot.com/wa/'
answer = web.get(uri + web.urllib.quote(query)) answer = web.get(uri + web.urllib.quote(query))
if answer: if answer:

View File

@ -26,6 +26,7 @@ def head(phenny, input):
if not uri.startswith('htt'): if not uri.startswith('htt'):
uri = 'http://' + uri uri = 'http://' + uri
# uri = uri.replace('#!', '?_escaped_fragment_=')
try: info = web.head(uri) try: info = web.head(uri)
except IOError: return phenny.say("Can't connect to %s" % 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: if not ':' in uri:
uri = 'http://' + uri uri = 'http://' + uri
uri = uri.replace('#!', '?_escaped_fragment_=')
try: try:
redirects = 0 redirects = 0

View File

@ -30,9 +30,9 @@ def mappings(uri):
def service(phenny, input, command, args): def service(phenny, input, command, args):
t = o.services[command] t = o.services[command]
template = t.replace('${args}', urllib.quote(args.encode('utf-8'))) template = t.replace('${args}', urllib.quote(args.encode('utf-8'), ''))
template = template.replace('${nick}', urllib.quote(input.nick)) template = template.replace('${nick}', urllib.quote(input.nick, ''))
uri = template.replace('${sender}', urllib.quote(input.sender)) uri = template.replace('${sender}', urllib.quote(input.sender, ''))
info = web.head(uri) info = web.head(uri)
if isinstance(info, list): if isinstance(info, list):

View File

@ -82,13 +82,13 @@ def f_remind(phenny, input):
if not phenny.reminders.has_key(tellee): if not phenny.reminders.has_key(tellee):
phenny.reminders[tellee] = [(teller, verb, timenow, msg)] phenny.reminders[tellee] = [(teller, verb, timenow, msg)]
else: else:
if len(phenny.reminders[tellee]) >= maximum: # if len(phenny.reminders[tellee]) >= maximum:
warn = True # warn = True
phenny.reminders[tellee].append((teller, verb, timenow, msg)) phenny.reminders[tellee].append((teller, verb, timenow, msg))
# @@ Stephanie's augmentation # @@ Stephanie's augmentation
response = "I'll pass that on when %s is around." % tellee_original response = "I'll pass that on when %s is around." % tellee_original
if warn: response += (" I'll have to use a pastebin, though, so " + # if warn: response += (" I'll have to use a pastebin, though, so " +
"your message may get lost.") # "your message may get lost.")
rand = random.random() rand = random.random()
if rand > 0.9999: response = "yeah, yeah" if rand > 0.9999: response = "yeah, yeah"
@ -138,29 +138,9 @@ def message(phenny, input):
phenny.say(line) phenny.say(line)
if reminders[maximum:]: if reminders[maximum:]:
try: phenny.say('Further messages sent privately')
if origin.sender in lispchannels: for line in reminders[maximum:]:
chan = origin.sender phenny.msg(tellee, line)
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)
if len(phenny.reminders.keys()) != remkeys: if len(phenny.reminders.keys()) != remkeys:
dumpReminders(phenny.tell_filename, phenny.reminders) # @@ tell dumpReminders(phenny.tell_filename, phenny.reminders) # @@ tell

View File

@ -24,7 +24,7 @@ r_redirect = re.compile(
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs', abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit', 'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit',
'syn', 'transl', 'sess', 'fl', 'Op'] \ 'syn', 'transl', 'sess', 'fl', 'Op', 'Dec'] \
+ list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \ + list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \
+ list('abcdefghijklmnopqrstuvwxyz') + list('abcdefghijklmnopqrstuvwxyz')
t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?=[\[ ][A-Z0-9]|\Z)|\Z)' t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?=[\[ ][A-Z0-9]|\Z)|\Z)'