Ejemplo n.º 1
0
    def synonym(self, irc, msg, args, words):
        """<word> [<word> ...]

        Gets a random synonym from the Moby Thesaurus (moby-thesaurus) database.

        If given many words, gets a random synonym for each of them.

        Quote phrases to have them treated as one lookup word.
        """
        try:
            server = conf.supybot.plugins.Dict.server()
            conn = dictclient.Connection(server)
        except socket.error as e:
            irc.error(utils.web.strError(e), Raise=True)

        dictionary = 'moby-thesaurus'
        response = []
        for word in words:
            definitions = conn.define(dictionary, word)
            if not definitions:
                asynonym = word
            else:
                defstr = definitions[0].getdefstr()
                synlist = ' '.join(defstr.split('\n')).split(': ', 1)[1].split(',')
                asynonym = random.choice(synlist).strip()
            response.append(asynonym)
        irc.reply(' '.join(response))
Ejemplo n.º 2
0
Archivo: plugin.py Proyecto: totte/aide
    def dict(self, irc, msg, args, words):
        """[<dictionary>] <word>

        Looks up the definition of <word> on the dictd server specified by
        the supybot.plugins.Dict.server config variable.
        """
        try:
            server = conf.supybot.plugins.Dict.server()
            conn = dictclient.Connection(server)
        except socket.error, e:
            irc.error(utils.web.strError(e), Raise=True)
Ejemplo n.º 3
0
    def random(self, irc, msg, args):
        """takes no arguments

        Returns a random valid dictionary.
        """
        try:
            server = conf.supybot.plugins.Dict.server()
            conn = dictclient.Connection(server)
            dbs = conn.getdbdescs().keys()
            irc.reply(utils.iter.choice(dbs))
        except socket.error as e:
            irc.error(utils.web.strError(e))
Ejemplo n.º 4
0
    def dictionaries(self, irc, msg, args):
        """takes no arguments

        Returns the dictionaries valid for the dict command.
        """
        try:
            server = conf.supybot.plugins.Dict.server()
            conn = dictclient.Connection(server)
            dbs = list(conn.getdbdescs().keys())
            dbs.sort()
            irc.reply(format('%L', dbs))
        except socket.error as e:
            irc.error(utils.web.strError(e))
Ejemplo n.º 5
0
    def dict(self, irc, msg, args, words):
        """[<dictionary>] <word>

        Looks up the definition of <word> on the dictd server specified by
        the supybot.plugins.Dict.server config variable.
        """
        try:
            server = conf.supybot.plugins.Dict.server()
            conn = dictclient.Connection(server)
        except socket.error as e:
            irc.error(utils.web.strError(e), Raise=True)
        dbs = set(conn.getdbdescs())
        if words[0] in dbs:
            dictionary = words.pop(0)
        else:
            default = self.registryValue('default', msg.args[0])
            if default in dbs:
                dictionary = default
            else:
                if default:
                    self.log.info(
                        'Default dict for %s is not a supported '
                        'dictionary: %s.', msg.args[0], default)
                dictionary = '*'
        if not words:
            irc.error(_('You must give a word to define.'), Raise=True)
        word = ' '.join(words)
        definitions = conn.define(dictionary, word)
        dbs = set()
        if not definitions:
            if dictionary == '*':
                irc.reply(
                    format(_('No definition for %q could be found.'), word))
            else:
                irc.reply(
                    format(_('No definition for %q could be found in '
                             '%s'), word, ircutils.bold(dictionary)))
            return
        L = []
        for d in definitions:
            dbs.add(ircutils.bold(d.getdb().getname()))
            (db, s) = (d.getdb().getname(), d.getdefstr())
            db = ircutils.bold(db)
            s = utils.str.normalizeWhitespace(s).rstrip(';.,')
            L.append('%s: %s' % (db, s))
        utils.sortBy(len, L)
        if dictionary == '*' and len(dbs) > 1:
            s = format(_('%L responded: %s'), list(dbs), '; '.join(L))
        else:
            s = '; '.join(L)
        irc.reply(s)
Ejemplo n.º 6
0
Archivo: plugin.py Proyecto: totte/aide
    def synonym(self, irc, msg, args, words):
        """<word> [<word> ...]

        Gets a random synonym from the Moby Thesaurus (moby-thes) database.

        If given many words, gets a random synonym for each of them.

        Quote phrases to have them treated as one lookup word.
        """
        try:
            server = conf.supybot.plugins.Dict.server()
            conn = dictclient.Connection(server)
        except socket.error, e:
            irc.error(utils.web.strError(e), Raise=True)