Create general autofill table and category util functions. Update table class to have get categories function.

This commit is contained in:
alwayscompiling
2022-11-17 14:50:48 -05:00
parent 1858f0c37d
commit 06b46ef27c
3 changed files with 69 additions and 13 deletions
+53
View File
@@ -10,6 +10,59 @@ from classes.category import Category # pylint: disable=import-error
from classes.table import Table # pylint: disable=import-error
def autofill_categories(guild_id: int, table_name: str, category_begin: str) -> "list[str]":
"""
Returns all category names that start with category_begin.
If category_begin is empty, returns list of all category names.
Args:
guild_id (int): Guild id that holds the table and categories.
table_name (str): Table name to search in.
category_begin (str): The beginning of a category name to search with. Can be empty.
Returns:
list[str]: List of all category names that start with category_begin.
"""
# if string empty, return all category names
if not category_begin:
return highscores_data.get_guild(guild_id).get_table(table_name).get_categories().keys()
# else find all categories that start with category_begin
categories = [
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
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.
Args:
guild_id (int): Guild id that holds the tables.
table_begin (str): The beginning of a table name to search with. Can be empty.
Returns:
list[str]: List of table names that start with table_begin.
"""
# if string empty, return all table names
if not table_begin:
return highscores_data.get_guild(guild_id).get_tables().keys()
# else find all tables that start with table_begin
tables = [
table
for table in highscores_data.get_guild(guild_id).get_tables().keys()
if table.lower().startswith(table_begin.lower())
]
return tables
def format_highscore_message(guild: Guild, table: Table) -> str:
"""
Creates a formatted string for a boss's highscore discord message.