diff --git a/irc.py b/irc.py index 38fe886..e5bfdc3 100755 --- a/irc.py +++ b/irc.py @@ -43,9 +43,12 @@ class Bot(asynchat.async_chat): def __write(self, args, text=None): # print '%r %r %r' % (self, args, text) - if text is not None: - self.push(' '.join(args) + ' :' + text + '\r\n') - else: self.push(' '.join(args) + '\r\n') + try: + if text is not None: + self.push(' '.join(args) + ' :' + text + '\r\n') + else: self.push(' '.join(args) + '\r\n') + except IndexError: + pass def write(self, args, text=None): # This is a safe version of __write diff --git a/modules/dict.py b/modules/dict.py index 61fcee9..df9025d 100755 --- a/modules/dict.py +++ b/modules/dict.py @@ -109,7 +109,7 @@ def dict(phenny, input): result = input.group(2).encode('utf-8') + ' - ' for key in sorted(results.keys()): if results[key]: - result += key + ' 1. ' + results[key][0] + result += (key or '') + ' 1. ' + results[key][0] if len(results[key]) > 1: result += ', 2. ' + results[key][1] result += '; ' diff --git a/modules/translate.py b/modules/translate.py index 23ce7e9..27bd094 100755 --- a/modules/translate.py +++ b/modules/translate.py @@ -11,7 +11,7 @@ http://inamidst.com/phenny/ import re, time import web -r_translation = re.compile(r'
([^<]+)
') +r_translation = re.compile(r'
([^<]+)
') def guess_language(phrase): languages = { @@ -40,15 +40,17 @@ def guess_language(phrase): if '_' in lang: j = lang.find('_') lang = lang[:j] - try: return languages[lang] + try: return languages[lang].lower() except KeyError: - return lang + return lang.lower() return 'Moon Language' def translate(phrase, lang, target='en'): - babelfish = 'http://world.altavista.com/tr' + babelfish = 'http://uk.babelfish.yahoo.com/translate_txt' form = { + 'ei': 'UTF-8', 'doit': 'done', + 'fr': 'bf-home', 'intl': '1', 'tt': 'urltext', 'trtext': phrase, @@ -89,7 +91,7 @@ def tr(phenny, input): else: return phenny.reply('"%s" (%s -> %s)' % \ (translation, input, output)) - error = "I think it's %s, which I can't translate." + error = "I think it's %s, but I can't translate it currently." return phenny.reply(error % input.title()) # Otherwise, it's English, so mangle it for fun