Commit d3f5fd11 authored by Sébastien Dufromentel's avatar Sébastien Dufromentel
Browse files

Message parsing improved (but still room for improvements)

parent 8c064615
......@@ -50,18 +50,21 @@ def usernick(botnick, lang):
return None # Not a bot nick.
nick = botnick[:-len(lang)-1] # Cleaning…
return irc.strings.IRCFoldedCase(nick[:-1]+"]"
if usernick.endswith("|") else nick)
if nick.endswith("|") else nick[:-1])
def translate(message, target):
try: # Don't interrupt.
if message == "\o/":
return message
#TODO replace nick/nick[lang] correctly.
for nick in bots.keys():
if nick in message:
message = message.replace(nick, usernick(nick, target))
with urllib.request.urlopen(trans, urllib.parse.urlencode({ "source":
"auto", "target": target, "q": message }).encode()) as f:
return json.loads(f.read())["translatedText"]
except Exception: # Probably a server error.
return "�[ "+message+" ]�"
__import__("traceback").print_exc()
return message
class data(object):
def __init__(self, **args):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment