Create autofill functions for users in category and in table. Add function in category class to return a list of all users.
This commit is contained in:
+10
-3
@@ -128,9 +128,7 @@ class Category:
|
|||||||
else:
|
else:
|
||||||
self._scores_map[score.user] = score
|
self._scores_map[score.user] = score
|
||||||
|
|
||||||
self._scores_map = dict(
|
self._scores_map = dict(sorted(self._scores_map.items(), key=lambda x: x[1].value, reverse=not self.ascending))
|
||||||
sorted(self._scores_map.items(), key=lambda x: x[1].value, reverse=not self.ascending)
|
|
||||||
)
|
|
||||||
|
|
||||||
def clear(self) -> None:
|
def clear(self) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -139,6 +137,15 @@ class Category:
|
|||||||
"""
|
"""
|
||||||
self._scores_map.clear()
|
self._scores_map.clear()
|
||||||
|
|
||||||
|
def get_users(self) -> "list[str]":
|
||||||
|
"""
|
||||||
|
Returns list of users in this category.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]: List of all users in category.
|
||||||
|
"""
|
||||||
|
return self._scores_map.keys()
|
||||||
|
|
||||||
def get_user_score(self, user: str) -> Score:
|
def get_user_score(self, user: str) -> Score:
|
||||||
"""
|
"""
|
||||||
Gets a user's score. Returns None if user is not found.
|
Gets a user's score. Returns None if user is not found.
|
||||||
|
|||||||
+70
-18
@@ -23,22 +23,46 @@ def autofill_categories(guild_id: int, table_name: str, category_begin: str) ->
|
|||||||
Returns:
|
Returns:
|
||||||
list[str]: List of all category names that start with category_begin.
|
list[str]: List of all category names that start with category_begin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
categories_list = highscores_data.get_guild(guild_id).get_table(table_name).get_categories().keys()
|
||||||
|
|
||||||
# if string empty, return all category names
|
# if string empty, return all category names
|
||||||
if not category_begin:
|
if not category_begin:
|
||||||
return highscores_data.get_guild(guild_id).get_table(table_name).get_categories().keys()
|
return categories_list
|
||||||
|
|
||||||
# else find all categories that start with category_begin
|
# else find all categories that start with category_begin
|
||||||
categories = [
|
categories = [category for category in categories_list if category.lower().startswith(category_begin.lower())]
|
||||||
category
|
|
||||||
for category in highscores_data.get_guild(guild_id)
|
|
||||||
.get_table(table_name)
|
|
||||||
.get_categories()
|
|
||||||
.keys()
|
|
||||||
if category.lower().startswith(category_begin.lower())
|
|
||||||
]
|
|
||||||
return categories
|
return categories
|
||||||
|
|
||||||
|
|
||||||
|
def autofill_category_users(guild_id: int, table_name: str, category_name: str, user_begin: str) -> "list[str]":
|
||||||
|
"""
|
||||||
|
Returns list of users that are in the table and category that also start with the user_begin string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
guild_id (int): Guild id corresponding to table and category.
|
||||||
|
table_name (str): Table to look in for category.
|
||||||
|
category_name (str): Category to look in for users.
|
||||||
|
user_begin (str): Beginning of user name to search with. Can be empty.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]: List of users that start with user_begin.
|
||||||
|
"""
|
||||||
|
|
||||||
|
users_list: "list[str]" = (
|
||||||
|
highscores_data.get_guild(guild_id).get_table(table_name).get_category(category_name).get_users()
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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.lower().startswith(user_begin.lower())]
|
||||||
|
|
||||||
|
return users
|
||||||
|
|
||||||
|
|
||||||
def autofill_tables(guild_id: int, table_begin: str) -> "list[str]":
|
def autofill_tables(guild_id: int, table_begin: str) -> "list[str]":
|
||||||
"""
|
"""
|
||||||
Returns all table names that start with table_begin. If table_begin is empty, returns list of all table names.
|
Returns all table names that start with table_begin. If table_begin is empty, returns list of all table names.
|
||||||
@@ -50,19 +74,49 @@ def autofill_tables(guild_id: int, table_begin: str) -> "list[str]":
|
|||||||
Returns:
|
Returns:
|
||||||
list[str]: List of table names that start with table_begin.
|
list[str]: List of table names that start with table_begin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
tables_list = highscores_data.get_guild(guild_id).get_tables().keys()
|
||||||
|
|
||||||
# if string empty, return all table names
|
# if string empty, return all table names
|
||||||
if not table_begin:
|
if not table_begin:
|
||||||
return highscores_data.get_guild(guild_id).get_tables().keys()
|
return tables_list
|
||||||
|
|
||||||
# else find all tables that start with table_begin
|
# else find all tables that start with table_begin
|
||||||
tables = [
|
tables = [table for table in tables_list if table.lower().startswith(table_begin.lower())]
|
||||||
table
|
|
||||||
for table in highscores_data.get_guild(guild_id).get_tables().keys()
|
|
||||||
if table.lower().startswith(table_begin.lower())
|
|
||||||
]
|
|
||||||
return tables
|
return tables
|
||||||
|
|
||||||
|
|
||||||
|
def autofill_table_users(guild_id: int, table_name: str, user_begin: str) -> "list[str]":
|
||||||
|
"""
|
||||||
|
Gathers all users in a table's categories and performs autofill function on it. This is an expensive
|
||||||
|
function.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
guild_id (int): Guild id corresponding to table and category.
|
||||||
|
table_name (str): Table to look in for categories.
|
||||||
|
user_begin (str): Beginning of user name to search with. Can be empty.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]: List of users that start with user_begin.
|
||||||
|
"""
|
||||||
|
|
||||||
|
user_set: set
|
||||||
|
|
||||||
|
for category in highscores_data.get_guild(guild_id).get_table(table_name).get_categories().values():
|
||||||
|
user_set = user_set | set(category.get_users())
|
||||||
|
|
||||||
|
users_list = list(user_set)
|
||||||
|
|
||||||
|
# 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.lower().startswith(user_begin.lower())]
|
||||||
|
|
||||||
|
return users
|
||||||
|
|
||||||
|
|
||||||
def format_highscore_message(guild: Guild, table: Table) -> str:
|
def format_highscore_message(guild: Guild, table: Table) -> str:
|
||||||
"""
|
"""
|
||||||
Creates a formatted string for a boss's highscore discord message.
|
Creates a formatted string for a boss's highscore discord message.
|
||||||
@@ -110,9 +164,7 @@ def format_highscore_message(guild: Guild, table: Table) -> str:
|
|||||||
return ret_string + "```"
|
return ret_string + "```"
|
||||||
|
|
||||||
|
|
||||||
async def send_highscore_message(
|
async def send_highscore_message(channel: nextcord.TextChannel, guild: Guild, table: Table) -> nextcord.Message:
|
||||||
channel: nextcord.TextChannel, guild: Guild, table: Table
|
|
||||||
) -> nextcord.Message:
|
|
||||||
"""
|
"""
|
||||||
Function takes care of checking if a message exists for a table.
|
Function takes care of checking if a message exists for a table.
|
||||||
Creates and sends/edits the message.
|
Creates and sends/edits the message.
|
||||||
|
|||||||
Reference in New Issue
Block a user