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)
评论列表
文章目录