class Translator(object): def __init__(self, server): self.google_translator = GoogleTranslator() xmap(server, 'CMSG', self.translate) @regcmd('@g (?P<lang1>.+?) (?P<lang2>.+?) (?P<data>.+)$') def translate(self, server, nick, user, host, target, msg, lang1, lang2, data): data = self.google_translator.translate(data, lang1, lang2) send_msg(server, target, data)
def __init__(self, server): self.google_translator = GoogleTranslator() xmap(server, 'CMSG', self.translate)
Commands ======== Command: @polyglot-add lang_x lang_y ident Description: Whenever an user with ident types it translates from lang_x to lang_y. Command: @polyglot-del lang_x lang_y ident Description: Remove the user with ident from the list of users to have their msgs to be translated. """ from untwisted.network import spawn, xmap, zmap from libdict import GoogleTranslator from untwisted.plugins.irc import send_msg from ameliabot.cmd import command source = GoogleTranslator() def install(server): xmap(server, 'CMSG', split) xmap(server, 'CMSG', add) xmap(server, 'CMSG', rm) @command('@polyglot-add lang_x lang_y ident') def add(server, nick, user, host, target, msg, lang_x, lang_y, ident): xmap(server, ident, listen, lang_x, lang_y) @command('@polyglot-del lang_x lang_y ident') def rm(server, nick, user, host, target, msg, lang_x, lang_y, ident):