Fix for Windows, and some more helpful error messages.
parent
87b9866c7c
commit
68f2036546
|
@ -36,7 +36,10 @@ def run_phenny(config):
|
||||||
p = bot.Phenny(config)
|
p = bot.Phenny(config)
|
||||||
p.run(config.host, config.port)
|
p.run(config.host, config.port)
|
||||||
|
|
||||||
Watcher()
|
try: Watcher()
|
||||||
|
except Exception, e:
|
||||||
|
print >> sys.stderr, 'Warning:', e, '(in __init__.py)'
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try: connect(config)
|
try: connect(config)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
2
bot.py
2
bot.py
|
@ -55,7 +55,7 @@ class Phenny(irc.Bot):
|
||||||
name = os.path.basename(filename)[:-3]
|
name = os.path.basename(filename)[:-3]
|
||||||
try: module = imp.load_source(name, filename)
|
try: module = imp.load_source(name, filename)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print >> sys.stderr, "Error loading %s: %s" % (name, e)
|
print >> sys.stderr, "Error loading %s: %s (in bot.py)" % (name, e)
|
||||||
else:
|
else:
|
||||||
if hasattr(module, 'setup'):
|
if hasattr(module, 'setup'):
|
||||||
module.setup(self)
|
module.setup(self)
|
||||||
|
|
|
@ -37,13 +37,8 @@ def translate(text, input, output):
|
||||||
pair = input + '%7C' + output
|
pair = input + '%7C' + output
|
||||||
bytes = web.get(uri + '?q=' + q + '&v=1.0&langpair=' + pair)
|
bytes = web.get(uri + '?q=' + q + '&v=1.0&langpair=' + pair)
|
||||||
result = json(bytes)
|
result = json(bytes)
|
||||||
try: msg = result['responseData']['translatedText']
|
try: return result['responseData']['translatedText'].encode('cp1252')
|
||||||
except Exception:
|
except Exception: return None
|
||||||
msg = 'The %s to %s translation failed, sorry!' % (input, output)
|
|
||||||
else:
|
|
||||||
msg = msg.encode('cp1252').replace(''', "'")
|
|
||||||
msg = '"%s" (%s to %s, translate.google.com)' % (msg, input, output)
|
|
||||||
return msg
|
|
||||||
|
|
||||||
def tr(phenny, context):
|
def tr(phenny, context):
|
||||||
"""Translates a phrase, with an optional language hint."""
|
"""Translates a phrase, with an optional language hint."""
|
||||||
|
@ -63,6 +58,11 @@ def tr(phenny, context):
|
||||||
|
|
||||||
if input != output:
|
if input != output:
|
||||||
msg = translate(phrase, input, output)
|
msg = translate(phrase, input, output)
|
||||||
|
if msg:
|
||||||
|
msg = msg.replace(''', "'")
|
||||||
|
msg = '"%s" (%s to %s, translate.google.com)' % (msg, input, output)
|
||||||
|
else: msg = 'The %s to %s translation failed, sorry!' % (input, output)
|
||||||
|
|
||||||
phenny.reply(msg)
|
phenny.reply(msg)
|
||||||
else: phenny.reply('Ehwhatnow?')
|
else: phenny.reply('Ehwhatnow?')
|
||||||
|
|
||||||
|
@ -70,5 +70,25 @@ tr.rule = ('$nick', ur'(?:([a-z]{2}) +)?(?:([a-z]{2}) +)?["“](.+?)["”]\? *$'
|
||||||
tr.example = '$nickname: "mon chien"? or $nickname: fr "mon chien"?'
|
tr.example = '$nickname: "mon chien"? or $nickname: fr "mon chien"?'
|
||||||
tr.priority = 'low'
|
tr.priority = 'low'
|
||||||
|
|
||||||
|
def mangle(phenny, input):
|
||||||
|
phrase = input.group(2).encode('utf-8')
|
||||||
|
for lang in ['fr', 'de', 'es', 'it', 'ja']:
|
||||||
|
backup = phrase
|
||||||
|
phrase = translate(phrase, 'en', lang)
|
||||||
|
if not phrase:
|
||||||
|
phrase = backup
|
||||||
|
break
|
||||||
|
__import__('time').sleep(0.5)
|
||||||
|
|
||||||
|
backup = phrase
|
||||||
|
phrase = translate(phrase, lang, 'en')
|
||||||
|
if not phrase:
|
||||||
|
phrase = backup
|
||||||
|
break
|
||||||
|
__import__('time').sleep(0.5)
|
||||||
|
|
||||||
|
phenny.reply(phrase or 'ERRORS SRY')
|
||||||
|
mangle.commands = ['mangle']
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print __doc__.strip()
|
print __doc__.strip()
|
||||||
|
|
|
@ -9,7 +9,7 @@ http://inamidst.com/phenny/
|
||||||
|
|
||||||
def replaced(phenny, input):
|
def replaced(phenny, input):
|
||||||
command = input.group(1)
|
command = input.group(1)
|
||||||
response = {
|
responses = {
|
||||||
'cp': '.cp has been replaced by .u',
|
'cp': '.cp has been replaced by .u',
|
||||||
'pc': '.pc has been replaced by .u',
|
'pc': '.pc has been replaced by .u',
|
||||||
'unicode': '.unicode has been replaced by .u',
|
'unicode': '.unicode has been replaced by .u',
|
||||||
|
@ -22,10 +22,11 @@ def replaced(phenny, input):
|
||||||
'thesaurus': ".thesaurus hasn't been ported to my new codebase yet",
|
'thesaurus': ".thesaurus hasn't been ported to my new codebase yet",
|
||||||
'rates': "moon wanter. moOOoon wanter!",
|
'rates': "moon wanter. moOOoon wanter!",
|
||||||
'web': 'the .web command has been removed; ask sbp for details',
|
'web': 'the .web command has been removed; ask sbp for details',
|
||||||
'mangle': ".mangle hasn't been ported to my new codebase yet",
|
|
||||||
'origin': ".origin hasn't been ported to my new codebase yet"
|
'origin': ".origin hasn't been ported to my new codebase yet"
|
||||||
}[command]
|
}
|
||||||
phenny.reply(response)
|
try: response = responses[command]
|
||||||
|
except KeyError: return
|
||||||
|
else: phenny.reply(response)
|
||||||
replaced.commands = [
|
replaced.commands = [
|
||||||
'cp', 'pc', 'unicode', 'compare', 'map', 'acronym', 'img',
|
'cp', 'pc', 'unicode', 'compare', 'map', 'acronym', 'img',
|
||||||
'v', 'validate', 'thesaurus', 'rates', 'web', 'mangle', 'origin'
|
'v', 'validate', 'thesaurus', 'rates', 'web', 'mangle', 'origin'
|
||||||
|
|
Loading…
Reference in New Issue