def def_masl(self, conn, event, match): if event.dst != event.mynick: url = match.group('url') if len(url) >= 50: desc = 'posted by %s to %s on %s' % \ (event.src, event.dst, time.ctime()) self.reply(conn, event, masl.shorten(url, desc))
def cmd_translate(self, conn, event, match): """translate [<lang>2<lang>:] <msg> -- translate between languages""" msg = match.group('msg').strip() fl, tl = match.group('from'), match.group('to') if fl == '': fl = 'auto' if tl == '': tl = 'en' if msg.startswith('http'): url = 'http://google.com/translate?' + \ urllib.urlencode({ 'u':msg, 'sl':fl, 'tl':tl }) desc = 'translation posted by %s to %s on %s' % \ (event.src, event.dst, time.ctime()) self.reply(conn, event, masl.shorten(url, desc)) else: txt = translate.translate(fl, tl, msg) if txt: txt = txt.translate(self.umap).encode('ascii', 'ignore') self.reply(conn, event, txt) else: self.reply(conn, event, 'sorry %s, i dunno' % event.src)