coins.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:jose 作者: lnmds 项目源码 文件源码
def guild_accounts(self, guild: discord.Guild,
                             field='amount') -> list:
        """Fetch all accounts that reference users that are in the guild.

        Uses caching.
        """

        lock = self.gacct_locks[guild.id]
        await lock

        accounts = []

        try:
            userids = None
            using_cache = False
            if guild.id in self.acct_cache:
                userids = self.acct_cache[guild.id]
                using_cache = True
            else:
                userids = [m.id for m in guild.members]

            for uid in userids:
                account = await self.get_account(uid)

                if account:
                    accounts.append(account)

                    if not using_cache:
                        self.acct_cache[guild.id].append(uid)
        finally:
            lock.release()

        # sanity check
        if lock.locked():
            lock.release()

        return sorted(accounts, key=lambda account: float(account[field]),
                      reverse=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号