run ruff check --fix
This commit is contained in:
+15
-25
@@ -31,7 +31,6 @@ def autofill_categories(
|
||||
Returns:
|
||||
dict[str, str]: List of all category names that start with category_begin.
|
||||
"""
|
||||
|
||||
with Session(engine) as session:
|
||||
# search database for all category names
|
||||
subq = (
|
||||
@@ -42,7 +41,7 @@ def autofill_categories(
|
||||
)
|
||||
cat_group_alias = aliased(CategoryGroup, subq)
|
||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
||||
categories_dict: "dict[str, str]" = {
|
||||
categories_dict: dict[str, str] = {
|
||||
cat.CategoryName: str(cat.CategoryId) for cat in session.scalars(stmt)
|
||||
}
|
||||
|
||||
@@ -52,7 +51,7 @@ def autofill_categories(
|
||||
|
||||
# else find all categories that start with category_begin
|
||||
# TODO is it better to have sql handle the starts with or python?
|
||||
categories: "dict[str, str]" = {
|
||||
categories: dict[str, str] = {
|
||||
cat_name: cat_id
|
||||
for cat_name, cat_id in categories_dict.items()
|
||||
if category_begin.lower() in cat_name.lower()
|
||||
@@ -71,13 +70,12 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
||||
Returns:
|
||||
dict[str, str]: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
||||
"""
|
||||
|
||||
with Session(engine) as session:
|
||||
# Select all groups in guild.
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
||||
|
||||
# dict has to have key values of same type for discord.
|
||||
group_dict: "dict[str, str]" = {
|
||||
group_dict: dict[str, str] = {
|
||||
group.GroupName: str(group.GroupId) for group in session.scalars(stmt)
|
||||
}
|
||||
|
||||
@@ -86,7 +84,7 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
||||
return dict(list(group_dict.items())[:25])
|
||||
|
||||
# else find all groups that start with group_begin
|
||||
groups: "dict[str, str]" = {
|
||||
groups: dict[str, str] = {
|
||||
group_name: group_id
|
||||
for group_name, group_id in group_dict.items()
|
||||
if group_begin.lower() in group_name.lower()
|
||||
@@ -111,7 +109,6 @@ def autofill_users_in_group_category(
|
||||
Returns:
|
||||
list[str]: List of users that start with user_begin.
|
||||
"""
|
||||
|
||||
with Session(engine) as session:
|
||||
# get all categories in the group
|
||||
subq = (
|
||||
@@ -142,14 +139,14 @@ def autofill_users_in_group_category(
|
||||
Score.CategoryId == category.CategoryId
|
||||
)
|
||||
|
||||
users_list: "list[str]" = list(session.scalars(stmt))
|
||||
users_list: list[str] = list(session.scalars(stmt))
|
||||
|
||||
# if string empty, return all users
|
||||
if not user_begin:
|
||||
return users_list[:25]
|
||||
|
||||
# else find all users that start with user_begin
|
||||
users: "list[str]" = [
|
||||
users: list[str] = [
|
||||
user for user in users_list if user_begin.lower() in user.lower()
|
||||
]
|
||||
|
||||
@@ -167,7 +164,6 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
||||
Returns:
|
||||
list[str]: All users with submissions in the guild.
|
||||
"""
|
||||
|
||||
with Session(engine) as session:
|
||||
group_ids = select(CategoryGroup.GroupId).where(
|
||||
CategoryGroup.GuildId == guild_id
|
||||
@@ -178,14 +174,14 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
||||
stmt = select(distinct(Score.UserName)).where(
|
||||
Score.CategoryId.in_(category_ids)
|
||||
)
|
||||
users_list: "list[str]" = list(session.scalars(stmt))
|
||||
users_list: list[str] = list(session.scalars(stmt))
|
||||
|
||||
# if string empty, return all users
|
||||
if not user_begin:
|
||||
return users_list[:25]
|
||||
|
||||
# else find all users that start with user_begin
|
||||
users: "list[str]" = [
|
||||
users: list[str] = [
|
||||
user for user in users_list if user_begin.lower() in user.lower()
|
||||
]
|
||||
|
||||
@@ -205,7 +201,6 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
Returns:
|
||||
str: Formatted string for discord message
|
||||
"""
|
||||
|
||||
ret_string = f"**{group.GroupName}**\n```"
|
||||
|
||||
stmt = select(Guild).where(Guild.GuildId == group.GuildId)
|
||||
@@ -227,8 +222,7 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
max_cat_size: int = 0
|
||||
pad_length = group.PadLength
|
||||
for cat in session.scalars(stmt):
|
||||
if cat.Size > max_cat_size:
|
||||
max_cat_size = cat.Size
|
||||
max_cat_size = max(cat.Size, max_cat_size)
|
||||
categories.append(cat)
|
||||
category_ids.append(cat.CategoryId)
|
||||
|
||||
@@ -240,7 +234,7 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
|
||||
# this list is what will be printed in the discord message
|
||||
# first string will be category list, others will be score printouts
|
||||
str_list: "list[str]" = ["" for i in range(max_cat_size + 1)]
|
||||
str_list: list[str] = ["" for i in range(max_cat_size + 1)]
|
||||
groups_df = d_f.groupby("CategoryId")
|
||||
|
||||
# TODO figure out how to have less nests.
|
||||
@@ -275,12 +269,11 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
ind + 1,
|
||||
pad_length,
|
||||
)
|
||||
# if not enough entries, pad out
|
||||
elif ind + 1 <= category.Size:
|
||||
str_list[ind + 1] += f"{ind + 1}: ".ljust(pad_length, " ")
|
||||
else:
|
||||
# if not enough entries, pad out
|
||||
if ind + 1 <= category.Size:
|
||||
str_list[ind + 1] += f"{ind + 1}: ".ljust(pad_length, " ")
|
||||
else:
|
||||
str_list[ind + 1] += "".ljust(pad_length, " ")
|
||||
str_list[ind + 1] += "".ljust(pad_length, " ")
|
||||
else:
|
||||
for ind in range(max_cat_size):
|
||||
if ind + 1 <= category.Size:
|
||||
@@ -379,7 +372,6 @@ async def send_highscore_message(
|
||||
Returns:
|
||||
nextcord.Message: Message object that was posted with group contents.
|
||||
"""
|
||||
|
||||
highscore_string = format_highscore_message(session, group)
|
||||
channel = guild.get_channel(group.ChannelId)
|
||||
|
||||
@@ -413,7 +405,6 @@ async def submit_score(
|
||||
username (str): The user who submitted the score.
|
||||
score (str): Score to submit. Need to convert to correct type.
|
||||
"""
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == category_id)
|
||||
is_time_record = session.scalar(stmt)
|
||||
@@ -454,10 +445,9 @@ def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
||||
guild_id (int): Guild id to add config to
|
||||
config_str (str): Config name to add
|
||||
"""
|
||||
|
||||
with Session(engine) as session:
|
||||
with open(
|
||||
f"example_config/{config_str}.json", encoding="utf-8", mode="r"
|
||||
f"example_config/{config_str}.json", encoding="utf-8"
|
||||
) as file:
|
||||
config = json.load(file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user