• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.sortBy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中supybot.utils.sortBy函数的典型用法代码示例。如果您正苦于以下问题:Python sortBy函数的具体用法?Python sortBy怎么用?Python sortBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sortBy函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: nicks

    def nicks(self, irc, msg, args, channel, optlist):
        """[<channel>] [--count]

        Returns the nicks in <channel>.  <channel> is only necessary if the
        message isn't sent in the channel itself. Returns only the number of
        nicks if --count option is provided.
        """
        # Make sure we don't elicit information about private channels to
        # people or channels that shouldn't know
        capability = ircdb.makeChannelCapability(channel, 'op')
        hostmask = irc.state.nickToHostmask(msg.nick)
        if 's' in irc.state.channels[channel].modes and \
            msg.args[0] != channel and \
            not ircdb.checkCapability(hostmask, capability) and \
            (ircutils.isChannel(msg.args[0]) or \
             msg.nick not in irc.state.channels[channel].users):
            irc.error(_('You don\'t have access to that information.'),
                    Raise=True)
        L = list(irc.state.channels[channel].users)
        keys = [option for (option, arg) in optlist]
        if 'count' not in keys:
            utils.sortBy(str.lower, L)
            private = self.registryValue("nicksInPrivate", channel)
            irc.reply(utils.str.commaAndify(L), private=private)
        else:
            irc.reply(str(len(L)))
开发者ID:Ban3,项目名称:Limnoria,代码行数:26,代码来源:plugin.py


示例2: _oldnotes

    def _oldnotes(self, irc, msg, sender):
        try:
            user = ircdb.users.getUser(msg.prefix)
        except KeyError:
            irc.errorNotRegistered()
            return

        def p(note):
            return note.to == user.id and note.read

        if sender:
            originalP = p

            def p(note):
                return originalP(note) and note.frm == sender.id

        notes = list(self.db.select(p))
        if not notes:
            irc.reply("I couldn't find any matching read notes " "for your user.")
        else:
            utils.sortBy(operator.attrgetter("id"), notes)
            notes.reverse()
            ids = [self._formatNoteId(msg, note) for note in notes]
            ids = self._condense(ids)
            irc.reply(format("%L.", ids))
开发者ID:the1glorfindel,项目名称:PoohBot,代码行数:25,代码来源:plugin.py


示例3: list

    def list(self, irc, msg, args, optlist, glob):
        """[--capability=<capability>] [<glob>]

        Returns the valid registered usernames matching <glob>.  If <glob> is
        not given, returns all registered usernames.
        """
        predicates = []
        for (option, arg) in optlist:
            if option == 'capability':
                def p(u, cap=arg):
                    try:
                        return u._checkCapability(cap)
                    except KeyError:
                        return False
                predicates.append(p)
        if glob:
            r = re.compile(fnmatch.translate(glob), re.I)
            def p(u):
                return r.match(u.name) is not None
            predicates.append(p)
        users = []
        for u in ircdb.users.itervalues():
            for predicate in predicates:
                if not predicate(u):
                    break
            else:
                users.append(u.name)
        if users:
            utils.sortBy(str.lower, users)
            irc.reply(format('%L', users))
        else:
            if predicates:
                irc.reply('There are no matching registered users.')
            else:
                irc.reply('There are no registered users.')
开发者ID:Kefkius,项目名称:mazabot,代码行数:35,代码来源:plugin.py


示例4: nicks

    def nicks(self, irc, msg, args, channel, optlist):
        """[<channel>] [--count]

        Returns the nicks in <channel>.  <channel> is only necessary if the
        message isn't sent in the channel itself. Returns only the number of
        nicks if --count option is provided.
        """
        # Make sure we don't elicit information about private channels to
        # people or channels that shouldn't know
        if 's' in irc.state.channels[channel].modes and \
            msg.args[0] != channel and \
            (ircutils.isChannel(msg.args[0]) or \
             msg.nick not in irc.state.channels[channel].users):
            irc.error(_('You don\'t have access to that information.'),
                    Raise=True)
        L = list(irc.state.channels[channel].users)
        keys = [option for (option, arg) in optlist]
        if 'count' not in keys:
            irc.reply(channel)
            irc.reply(optlist)
            irc.reply(keys)
            irc.reply(args)
            utils.sortBy(str.lower, L)
            irc.reply(utils.str.commaAndify(L))
        else:
            irc.reply(args)
            irc.reply(channel)
            irc.reply(optlist)
            irc.reply(keys)
            irc.reply(str(len(L)))
开发者ID:kg-bot,项目名称:SupyBot,代码行数:30,代码来源:plugin.py


示例5: search

    def search(self, irc, msg, args, user, optlist, glob):
        """[--{regexp} <value>] [--sent] [<glob>]

        Searches your received notes for ones matching <glob>.  If --regexp is
        given, its associated value is taken as a regexp and matched against
        the notes.  If --sent is specified, only search sent notes.
        """
        criteria = []
        def to(note):
            return note.to == user.id
        def frm(note):
            return note.frm == user.id
        own = to
        for (option, arg) in optlist:
            if option == 'regexp':
                criteria.append(arg.search)
            elif option == 'sent':
                own = frm
        if glob:
            glob = fnmatch.translate(glob)
            # ignore the trailing $ fnmatch.translate adds to the regexp
            criteria.append(re.compile(glob[:-1]).search)
        def match(note):
            for p in criteria:
                if not p(note.text):
                    return False
            return True
        notes = list(self.db.select(lambda n: match(n) and own(n)))
        if not notes:
            irc.reply('No matching notes were found.')
        else:
            utils.sortBy(operator.attrgetter('id'), notes)
            ids = [self._formatNoteId(msg, note) for note in notes]
            ids = self._condense(ids)
            irc.reply(format('%L', ids))
开发者ID:Kefkius,项目名称:mazabot,代码行数:35,代码来源:plugin.py


示例6: getTopUsers

 def getTopUsers(self, channel, word, n):
     L = [(id, d[word]) for ((chan, id), d) in self.iteritems()
          if ircutils.nickEqual(channel, chan) and word in d]
     utils.sortBy(lambda (_, i): i, L)
     L = L[-n:]
     L.reverse()
     return L
开发者ID:D0MF,项目名称:supybot-plugins-1,代码行数:7,代码来源:plugin.py


示例7: search

    def search(self, irc, msg, args, user, optlist, glob):
        """[--{regexp} <value>] [--sent] [<glob>]

        Searches your received notes for ones matching <glob>.  If --regexp is
        given, its associated value is taken as a regexp and matched against
        the notes.  If --sent is specified, only search sent notes.
        """
        criteria = []
        def to(note):
            return note.to == user.id
        def frm(note):
            return note.frm == user.id
        own = to
        for (option, arg) in optlist:
            if option == 'regexp':
                criteria.append(lambda x: commands.regexp_wrapper(x, reobj=arg, 
                        timeout=0.1, plugin_name = self.name(), fcn_name='search'))
            elif option == 'sent':
                own = frm
        if glob:
            glob = utils.python.glob2re(glob)
            criteria.append(re.compile(glob).search)
        def match(note):
            for p in criteria:
                if not p(note.text):
                    return False
            return True
        notes = list(self.db.select(lambda n: match(n) and own(n)))
        if not notes:
            irc.reply('No matching notes were found.')
        else:
            utils.sortBy(operator.attrgetter('id'), notes)
            ids = [self._formatNoteId(msg, note) for note in notes]
            ids = self._condense(ids)
            irc.reply(format('%L', ids))
开发者ID:Athemis,项目名称:Limnoria,代码行数:35,代码来源:plugin.py


示例8: networks

    def networks(self, irc, msg, args):
        """takes no arguments

        Returns the networks to which the bot is currently connected.
        """
        L = ['%s: %s' % (ircd.network, ircd.server) for ircd in world.ircs]
        utils.sortBy(str.lower, L)
        irc.reply(format('%L', L))
开发者ID:TingPing,项目名称:Limnoria,代码行数:8,代码来源:plugin.py


示例9: sortAuthors

 def sortAuthors():
     """
     Sort the list of 'long names' based on the number of contributions
     associated with each.
     """
     L = list(module.__contributors__.items())
     def negativeSecondElement(x):
         return -len(x[1])
     utils.sortBy(negativeSecondElement, L)
     return [t[0] for t in L]
开发者ID:Ban3,项目名称:Limnoria,代码行数:10,代码来源:plugin.py


示例10: wulist

    def wulist(self, irc, msg, args):
        """takes no arguments

        Returns the list of urls in the whitelist.
        """
        L = list(self.registryValue('urlWhitelist'))
        if L:
            utils.sortBy(str.lower, L)
            irc.reply(format('%L', L))
        else:
            irc.reply('There are no urls in the whitelist.')
开发者ID:nanotube,项目名称:supybot_fixes,代码行数:11,代码来源:plugin.py


示例11: channels

    def channels(self, irc, msg, args):
        """takes no arguments

        Returns the channels the bot is on.
        """
        L = irc.state.channels.keys()
        if L:
            utils.sortBy(ircutils.toLower, L)
            irc.reply(format('%L', L), private=True)
        else:
            irc.reply(_('I\'m not currently in any channels.'))
开发者ID:Ban3,项目名称:Limnoria,代码行数:11,代码来源:plugin.py


示例12: channels

    def channels(self, irc, msg, args):
        """takes no arguments

        Returns the channels the bot is on.  Must be given in private, in order
        to protect the secrecy of secret channels.
        """
        L = irc.state.channels.keys()
        if L:
            utils.sortBy(ircutils.toLower, L)
            irc.reply(format('%L', L))
        else:
            irc.reply(_('I\'m not currently in any channels.'))
开发者ID:frumiousbandersnatch,项目名称:Limnoria,代码行数:12,代码来源:plugin.py


示例13: do315

 def do315(self, irc, msg):
     mask = msg.args[1]
     if mask in self.whos:
         (replyIrc, msgs) = self.whos.pop(mask)
         nicks = []
         for msg in msgs:
             nicks.append(msg.args[5])
         utils.sortBy(ircutils.toLower, nicks)
         if nicks:
             replyIrc.reply(format('%s matched: %L.', len(nicks), nicks))
         else:
             replyIrc.reply('No users matched %s.' % mask)
开发者ID:D0MF,项目名称:supybot-plugins-1,代码行数:12,代码来源:plugin.py


示例14: nicks

    def nicks(self, irc, msg, args):
        """takes no arguments

        Returns the nicks that this plugin is configured to identify and ghost
        with.
        """
        L = list(self.registryValue('nicks'))
        if L:
            utils.sortBy(ircutils.toLower, L)
            irc.reply(format('%L', L))
        else:
            irc.reply('I\'m not currently configured for any nicks.')
开发者ID:MrTiggr,项目名称:supybot_fixes,代码行数:12,代码来源:plugin.py


示例15: list

    def list(self, irc, msg, args):
        """takes no arguments

        Returns the list of words being censored.
        """
        L = list(self.words())
        if L:
            self.filtering = False
            utils.sortBy(str.lower, L)
            irc.reply(format('%L', L))
        else:
            irc.reply(_('I\'m not currently censoring any bad words.'))
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:12,代码来源:plugin.py


示例16: glossary

    def glossary (self, irc, msg, args):
        """<no arguments>

        Returns a list of defined lookup words
        """
        words = []
        for (name, (text, url, _)) in self.abbr.items():
            words.append(name)
        if words:
            utils.sortBy(str.lower, words)
            irc.reply(format('Available definitions: %L', words))
        else:
            irc.reply('There are no words defined.')
开发者ID:KenjiE20,项目名称:ottdcoop-plugin,代码行数:13,代码来源:plugin.py


示例17: _list

 def _list(self, group):
     L = []
     for (vname, v) in group._children.iteritems():
         if hasattr(group, 'channelValue') and group.channelValue and \
            ircutils.isChannel(vname) and not v._children:
             continue
         if hasattr(v, 'channelValue') and v.channelValue:
             vname = '#' + vname
         if v._added and not all(ircutils.isChannel, v._added):
             vname = '@' + vname
         L.append(vname)
     utils.sortBy(str.lower, L)
     return L
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:13,代码来源:plugin.py


示例18: dict

    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 and \
                self.registryValue("showDictName", msg.args[0]):
            s = format(_('%L responded: %s'), list(dbs), '; '.join(L))
        else:
            s = '; '.join(L)
        irc.reply(s)
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:50,代码来源:plugin.py


示例19: todo

    def todo(self, irc, msg, args, user, taskid):
        """[<username>] [<task id>]

        Retrieves a task for the given task id.  If no task id is given, it
        will return a list of task ids that that user has added to their todo
        list.
        """
        try:
            u = ircdb.users.getUser(msg.prefix)
        except KeyError:
            u = None
        if u != user and not self.registryValue('allowThirdpartyReader'):
            irc.error(_('You are not allowed to see other users todo-list.'))
            return
        # List the active tasks for the given user
        if not taskid:
            try:
                tasks = self.db.getTodos(user.id)
                utils.sortBy(operator.attrgetter('priority'), tasks)
                tasks = [format(_('#%i: %s'), t.id, self._shrink(t.task))
                         for t in tasks]
                Todo = 'Todo'
                if len(tasks) != 1:
                    Todo = 'Todos'
                irc.reply(format(_('%s for %s: %L'),
                                 Todo, user.name, tasks))
            except dbi.NoRecordError:
                if u != user:
                    irc.reply(_('That user has no tasks in their todo list.'))
                else:
                    irc.reply(_('You have no tasks in your todo list.'))
                return
        # Reply with the user's task
        else:
            try:
                t = self.db.get(user.id, taskid)
                if t.active:
                    active = _('Active')
                else:
                    active = _('Inactive')
                if t.priority:
                    t.task += format(_(', priority: %i'), t.priority)
                at = time.strftime(conf.supybot.reply.format.time(),
                                   time.localtime(t.at))
                s = format(_('%s todo for %s: %s (Added at %s)'),
                           active, user.name, t.task, at)
                irc.reply(s)
            except dbi.NoRecordError:
                irc.errorInvalid(_('task id'), taskid)
开发者ID:limebot,项目名称:LimeBot,代码行数:49,代码来源:plugin.py


示例20: networks

    def networks(self, irc, msg, args, opts):
        """[--all]

        Returns the networks to which the bot is currently connected.
        If --all is given, also includes networks known by the bot,
        but not connected to.
        """
        opts = dict(opts)
        L = ["%s: %s" % (ircd.network, ircd.server) for ircd in world.ircs]
        if "all" in opts:
            for net in conf.supybot.networks._children.keys():
                if net not in [ircd.network for ircd in world.ircs]:
                    L.append("%s: (%s)" % (net, _("disconnected")))
        utils.sortBy(str.lower, L)
        irc.reply(format("%L", L))
开发者ID:carriercomm,项目名称:Limnoria,代码行数:15,代码来源:plugin.py



注:本文中的supybot.utils.sortBy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.timeElapsed函数代码示例发布时间:2022-05-27
下一篇:
Python utils.exnToString函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap