diff options
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/admin.py | 4 | ||||
-rwxr-xr-x | modules/etymology.py | 3 | ||||
-rwxr-xr-x | modules/head.py | 9 | ||||
-rwxr-xr-x | modules/info.py | 1 | ||||
-rwxr-xr-x | modules/tell.py | 8 | ||||
-rwxr-xr-x | modules/translate.py | 5 | ||||
-rwxr-xr-x | modules/wikipedia.py | 11 |
7 files changed, 27 insertions, 14 deletions
diff --git a/modules/admin.py b/modules/admin.py index 24b8fb6..e1dd908 100755 --- a/modules/admin.py +++ b/modules/admin.py @@ -42,7 +42,7 @@ def msg(phenny, input): if input.sender.startswith('#'): return if input.admin: phenny.msg(input.group(2), input.group(3)) -msg.rule = (['msg'], r'(#\S+) (.*)') +msg.rule = (['msg'], r'(#?\S+) (.*)') msg.priority = 'low' def me(phenny, input): @@ -51,7 +51,7 @@ def me(phenny, input): if input.admin: msg = '\x01ACTION %s\x01' % input.group(3) phenny.msg(input.group(2), msg) -me.rule = (['me'], r'(#\S+) (.*)') +me.rule = (['me'], r'(#?\S+) (.*)') me.priority = 'low' if __name__ == '__main__': diff --git a/modules/etymology.py b/modules/etymology.py index 52ae1bc..a26f06f 100755 --- a/modules/etymology.py +++ b/modules/etymology.py @@ -21,7 +21,8 @@ r_whitespace = re.compile(r'[\t\r\n ]+') abbrs = [ 'cf', 'lit', 'etc', 'Ger', 'Du', 'Skt', 'Rus', 'Eng', 'Amer.Eng', 'Sp', 'Fr', 'N', 'E', 'S', 'W', 'L', 'Gen', 'J.C', 'dial', 'Gk', - '19c', '18c', '17c', '16c', 'St', 'Capt' + '19c', '18c', '17c', '16c', 'St', 'Capt', 'obs', 'Jan', 'Feb', 'Mar', + 'Apr', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] t_sentence = r'^.*?(?<!%s)(?:\.(?= [A-Z0-9]|\Z)|\Z)' r_sentence = re.compile(t_sentence % ')(?<!'.join(abbrs)) diff --git a/modules/head.py b/modules/head.py index 2552d6f..c271de1 100755 --- a/modules/head.py +++ b/modules/head.py @@ -21,7 +21,8 @@ def head(phenny, input): else: uri, header = uri, None if not uri and hasattr(phenny, 'last_seen_uri'): - uri = phenny.last_seen_uri + try: uri = phenny.last_seen_uri[input.sender] + except KeyError: return phenny.say('?') try: info = web.head(uri) except IOError: return phenny.say("Can't connect to %s" % uri) @@ -67,9 +68,9 @@ def f_title(self, origin, match, args): uri = (uri or '').encode('utf-8') if not uri and hasattr(self, 'last_seen_uri'): - uri = self.last_seen_uri.get('#swhack') + uri = self.last_seen_uri.get(origin.sender) if not uri: - return phenny.msg(origin.sender, 'I need a URI to give the title of...') + return self.msg(origin.sender, 'I need a URI to give the title of...') if not ':' in uri: uri = 'http://' + uri @@ -145,7 +146,7 @@ def noteuri(phenny, input): if not hasattr(phenny.bot, 'last_seen_uri'): phenny.bot.last_seen_uri = {} phenny.bot.last_seen_uri[input.sender] = uri -noteuri.rule = r'.*(http://[^<> "]+)[,.]?' +noteuri.rule = r'.*(http://[^<> "\x01]+)[,.]?' noteuri.priority = 'low' if __name__ == '__main__': diff --git a/modules/info.py b/modules/info.py index a40a34f..a5113ba 100755 --- a/modules/info.py +++ b/modules/info.py @@ -49,6 +49,7 @@ def stats(phenny, input): ignore = set(['f_note', 'startup', 'message', 'noteuri']) for (name, user), count in phenny.stats.iteritems(): if name in ignore: continue + if not user: continue if not user.startswith('#'): try: users[user] += count diff --git a/modules/tell.py b/modules/tell.py index dc8ea46..ef9f171 100755 --- a/modules/tell.py +++ b/modules/tell.py @@ -65,7 +65,7 @@ def f_remind(phenny, input): msg = msg.encode('utf-8') tellee_original = tellee.rstrip(',:;') - tellee = tellee.lower() + tellee = tellee_original.lower() if not os.path.exists(phenny.tell_filename): return @@ -90,7 +90,7 @@ def f_remind(phenny, input): rand = random.random() if rand > 0.9999: response = "yeah, yeah" - elif rand > 0.999: response = "%s: yeah, sure, whatever" % teller + elif rand > 0.999: response = "yeah, sure, whatever" phenny.reply(response) elif teller.lower() == tellee: @@ -126,10 +126,10 @@ def message(phenny, input): reminders = [] remkeys = list(reversed(sorted(phenny.reminders.keys()))) for remkey in remkeys: - if not remkey.endswith('*'): + if not remkey.endswith('*') or remkey.endswith(':'): if tellee.lower() == remkey: reminders.extend(getReminders(phenny, channel, remkey, tellee)) - elif tellee.lower().startswith(remkey.rstrip('*')): + elif tellee.lower().startswith(remkey.rstrip('*:')): reminders.extend(getReminders(phenny, channel, remkey, tellee)) for line in reminders[:maximum]: diff --git a/modules/translate.py b/modules/translate.py index d90de43..f7cf0a2 100755 --- a/modules/translate.py +++ b/modules/translate.py @@ -68,9 +68,10 @@ def translate(phrase, lang, target='en'): def tr(phenny, input): """Translates a phrase, with an optional language hint.""" - input, output, phrase = input.groups() + original_input = input + input, output, phrase = original_input.groups() phrase = phrase.encode('utf-8') - if (len(phrase) > 350) and (not phenny.admin(input.nick)): + if (len(phrase) > 350) and (not original_input.admin): return phenny.reply('Phrase must be under 350 characters.') input = input or guess_language(phrase) diff --git a/modules/wikipedia.py b/modules/wikipedia.py index 540ba4a..ea32443 100755 --- a/modules/wikipedia.py +++ b/modules/wikipedia.py @@ -48,6 +48,10 @@ def search(term): print e return term + if isinstance(term, unicode): + term = term.encode('utf-8') + else: term = term.decode('utf-8') + term = term.replace('_', ' ') try: uri = search.result('site:en.wikipedia.org %s' % term) except IndexError: return term @@ -58,7 +62,12 @@ def search(term): def wikipedia(term, last=False): global wikiuri if not '%' in term: - bytes = web.get(wikiuri % urllib.quote(term)) + if isinstance(term, unicode): + t = term.encode('utf-8') + else: t = term + q = urllib.quote(t) + u = wikiuri % q + bytes = web.get(u) else: bytes = web.get(wikiuri % term) bytes = r_tr.sub('', bytes) |