Add autofill to get all users in guild.

This commit is contained in:
alwayscompiling
2022-12-01 17:42:29 -05:00
parent 439ad539a8
commit b9cc3b46bb
+26
View File
@@ -137,6 +137,32 @@ def autofill_users_in_group_category(
return users
def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
"""
Obtains and returns a list of all the users who have submitted to the guild's highscores.
Args:
guild_id (int): Id of the guild.
user_begin (str): Beginning of user name to search with. Can be empty.
Returns:
list[str]: All users with submissions in the guild.
"""
group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id).subquery()
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids)).subquery()
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
users_list: "list[str]" = list(session.scalars(stmt))
# if string empty, return all users
if not user_begin:
return users_list
# else find all users that start with user_begin
users = [user for user in users_list if user_begin.lower() in user.lower()]
return users
def format_highscore_message(group: CategoryGroup) -> str:
"""
Creates a formatted string for a boss's highscore discord message.