def __init__(self, irc): self.__parent = super(Makfa, self) self.__parent.__init__(irc) self.db = jbovlaste.Dictionary('data/jbovlaste-en.xml') self._camxes = Camxes()
class Makfa(callbacks.Plugin): """Add the help for "@plugin help Makfa" here This should describe *how* to use this plugin.""" def __init__(self, irc): self.__parent = super(Makfa, self) self.__parent.__init__(irc) self.db = jbovlaste.Dictionary('data/jbovlaste-en.xml') self._camxes = Camxes() def unnest(self, irc, msg, args, command): """<command> Execute a command and get the non-nested output. """ self.Proxy(irc.irc, msg, callbacks.tokenize(command)) unnest = wrap(unnest, ['text']) def unquote(self, irc, msg, args, opts, text): """[--number <integer>] <text> Extract the contents of a Lojban quote in a text, defaults to the last one (--number 0). """ number = -1 for (key, val) in opts: if key == 'number': number = val - 1 if '{' in text: irc.reply(re.findall(r'\{(.+?)\}', text)[number]) else: irc.reply(text) unquote = wrap(unquote, [getopts({'number': 'int'}), 'text']) def _cenlai(self, text): tokens = text.lower().replace('.', ' ').split() hit = [i in self.db for i in tokens] percentage = int(float(hit.count(True)) / len(tokens) * 100) return percentage def lastlojban(self, irc, msg, args, channel, nick, percent): """[channel] [nick] [percent] Get the last Lojban message as determined by potential-percentage. """ if not percent: percent = 40 for ircmsg in reversed(irc.state.history): if ircmsg.command == 'PRIVMSG': msgs = [ircmsg.args[1]] if '{' in msgs[0]: msgs = reversed(list(re.findall(r'\{(.+?)\}', msgs[0]))) for imsg in msgs: if self._cenlai(imsg) >= percent: if not channel or \ ircutils.strEqual(channel, ircmsg.args[0]): if not nick or \ ircutils.hostmaskPatternEqual(nick, ircmsg.nick): irc.reply(imsg) return lastlojban = wrap(lastlojban, [optional('channel'), optional('seenNick'), optional('positiveInt')]) def camxes(self, irc, msg, args, text): """<text> Get the grammatical portion of text with camxes. """ grammatical = self._camxes.parse(text) result = grammatical + '\x0304' + text[len(grammatical):] + '\x03' irc.reply(result) camxes = wrap(camxes, ['text'])