def user_top_list(self, count, server):
"""
Gets top <count> users on the server
:param count: length of the top list
:param server: the server
:return: a SelectQuery with users on the top list
"""
users = (self.models.User
.select()
.join(self.models.Channel, on=(self.models.Channel.id == self.models.Message.channel))
.join(self.models.Server, on=(self.models.Server.id == self.models.Channel.server))
.switch(self.models.User)
# peewee needs the ==
.where(self.models.Message.is_command == False,
self.models.User.is_bot == False,
self.models.Server.id == server)
.annotate(self.models.Message) # annotate alias to 'count'
.order_by(SQL('count').desc())
.limit(count))
return users
评论列表
文章目录