run ruff format
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
Commands for creating items in bot.
|
Commands for creating items in bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import exc, select
|
from sqlalchemy import exc, select
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
Commands for deleting groups/categories/scores in database and messages in discord..
|
Commands for deleting groups/categories/scores in database and messages in discord..
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import distinct, select
|
from sqlalchemy import distinct, select
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
Set command heirarchy.
|
Set command heirarchy.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
Contains view and helper functions for confirming and processing deletes.
|
Contains view and helper functions for confirming and processing deletes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from sqlalchemy import delete, select
|
from sqlalchemy import delete, select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|||||||
@@ -19,9 +19,7 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
|||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
|
|
||||||
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-username-update")
|
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-username-update")
|
||||||
async def deny_button(
|
async def deny_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
|
||||||
): # pylint: disable=unused-argument
|
|
||||||
"""
|
"""
|
||||||
Button for denying username update. Deletes message.
|
Button for denying username update. Deletes message.
|
||||||
|
|
||||||
@@ -32,9 +30,7 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
|||||||
await interaction.message.delete()
|
await interaction.message.delete()
|
||||||
|
|
||||||
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-username-update")
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-username-update")
|
||||||
async def approve_button(
|
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
|
||||||
): # pylint: disable=unused-argument
|
|
||||||
"""
|
"""
|
||||||
Button for approving username update. Tells guild data to update username, then updates
|
Button for approving username update. Tells guild data to update username, then updates
|
||||||
message to show it is complete.
|
message to show it is complete.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"""Views used for submission process."""
|
"""Views used for submission process."""
|
||||||
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|||||||
@@ -13,16 +13,12 @@ class VerificationView(nextcord.ui.View):
|
|||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
|
|
||||||
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission")
|
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission")
|
||||||
async def deny_button(
|
async def deny_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
|
||||||
): # pylint: disable=unused-argument
|
|
||||||
"""Button for denying score submission."""
|
"""Button for denying score submission."""
|
||||||
await interaction.message.delete()
|
await interaction.message.delete()
|
||||||
|
|
||||||
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
|
||||||
async def approve_button(
|
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
|
||||||
): # pylint: disable=unused-argument
|
|
||||||
"""Button for approving score submission."""
|
"""Button for approving score submission."""
|
||||||
for embed in interaction.message.embeds:
|
for embed in interaction.message.embeds:
|
||||||
content = embed.to_dict()
|
content = embed.to_dict()
|
||||||
@@ -38,7 +34,6 @@ class VerificationView(nextcord.ui.View):
|
|||||||
user = field["value"]
|
user = field["value"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
await submit_score(interaction, group_id, category_id, user, score)
|
await submit_score(interaction, group_id, category_id, user, score)
|
||||||
content = interaction.message.content
|
content = interaction.message.content
|
||||||
content += f"\nApproved by <@{interaction.user.id}>."
|
content += f"\nApproved by <@{interaction.user.id}>."
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Simple file to set up the sqlalchemy connection to database.
|
Simple file to set up the sqlalchemy connection to database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.automap import automap_base
|
from sqlalchemy.ext.automap import automap_base
|
||||||
|
|
||||||
|
|||||||
+18
-56
@@ -16,9 +16,7 @@ from utilities.sql_data_classes import Category, CategoryGroup, Guild, Score, en
|
|||||||
MAX_LINE_LENGTH = 142
|
MAX_LINE_LENGTH = 142
|
||||||
|
|
||||||
|
|
||||||
def autofill_categories(
|
def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "dict[str, str]":
|
||||||
guild_id: int, group_id: int, category_begin: str
|
|
||||||
) -> "dict[str, str]":
|
|
||||||
"""
|
"""
|
||||||
Returns all category names that start with category_begin.
|
Returns all category names that start with category_begin.
|
||||||
If category_begin is empty, returns list of all category names.
|
If category_begin is empty, returns list of all category names.
|
||||||
@@ -41,9 +39,7 @@ def autofill_categories(
|
|||||||
)
|
)
|
||||||
cat_group_alias = aliased(CategoryGroup, subq)
|
cat_group_alias = aliased(CategoryGroup, subq)
|
||||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
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)}
|
||||||
cat.CategoryName: str(cat.CategoryId) for cat in session.scalars(stmt)
|
|
||||||
}
|
|
||||||
|
|
||||||
# if string empty, return all category names
|
# if string empty, return all category names
|
||||||
if not category_begin:
|
if not category_begin:
|
||||||
@@ -52,9 +48,7 @@ def autofill_categories(
|
|||||||
# else find all categories that start with category_begin
|
# else find all categories that start with category_begin
|
||||||
# TODO is it better to have sql handle the starts with or python?
|
# 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
|
cat_name: cat_id for cat_name, cat_id in categories_dict.items() if category_begin.lower() in cat_name.lower()
|
||||||
for cat_name, cat_id in categories_dict.items()
|
|
||||||
if category_begin.lower() in cat_name.lower()
|
|
||||||
}
|
}
|
||||||
return dict(list(categories.items())[:25])
|
return dict(list(categories.items())[:25])
|
||||||
|
|
||||||
@@ -75,9 +69,7 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
|||||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
||||||
|
|
||||||
# dict has to have key values of same type for discord.
|
# 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)}
|
||||||
group.GroupName: str(group.GroupId) for group in session.scalars(stmt)
|
|
||||||
}
|
|
||||||
|
|
||||||
# if string empty, return all group names
|
# if string empty, return all group names
|
||||||
if not group_begin:
|
if not group_begin:
|
||||||
@@ -85,17 +77,13 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
|||||||
|
|
||||||
# else find all groups that start with group_begin
|
# else find all groups that start with group_begin
|
||||||
groups: dict[str, str] = {
|
groups: dict[str, str] = {
|
||||||
group_name: group_id
|
group_name: group_id for group_name, group_id in group_dict.items() if group_begin.lower() in group_name.lower()
|
||||||
for group_name, group_id in group_dict.items()
|
|
||||||
if group_begin.lower() in group_name.lower()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dict(list(groups.items())[:25])
|
return dict(list(groups.items())[:25])
|
||||||
|
|
||||||
|
|
||||||
def autofill_users_in_group_category(
|
def autofill_users_in_group_category(guild_id: int, group_id: int, category_id: int, user_begin: str) -> "list[str]":
|
||||||
guild_id: int, group_id: int, category_id: int, user_begin: str
|
|
||||||
) -> "list[str]":
|
|
||||||
"""
|
"""
|
||||||
Returns list of users that match user_begin. Either all users in group or just users in category if category is
|
Returns list of users that match user_begin. Either all users in group or just users in category if category is
|
||||||
not None. Might be expensive due to unioning all users in group.
|
not None. Might be expensive due to unioning all users in group.
|
||||||
@@ -121,9 +109,7 @@ def autofill_users_in_group_category(
|
|||||||
|
|
||||||
# If no category id, get all users in group.
|
# If no category id, get all users in group.
|
||||||
if category_id == 0:
|
if category_id == 0:
|
||||||
subq = select(Category.CategoryId).where(
|
subq = select(Category.CategoryId).where(Category.GroupId == category_group.GroupId)
|
||||||
Category.GroupId == category_group.GroupId
|
|
||||||
)
|
|
||||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(subq))
|
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(subq))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -135,9 +121,7 @@ def autofill_users_in_group_category(
|
|||||||
.subquery()
|
.subquery()
|
||||||
)
|
)
|
||||||
category = aliased(Category, subq)
|
category = aliased(Category, subq)
|
||||||
stmt = select(distinct(Score.UserName)).where(
|
stmt = select(distinct(Score.UserName)).where(Score.CategoryId == category.CategoryId)
|
||||||
Score.CategoryId == category.CategoryId
|
|
||||||
)
|
|
||||||
|
|
||||||
users_list: list[str] = list(session.scalars(stmt))
|
users_list: list[str] = list(session.scalars(stmt))
|
||||||
|
|
||||||
@@ -146,9 +130,7 @@ def autofill_users_in_group_category(
|
|||||||
return users_list[:25]
|
return users_list[:25]
|
||||||
|
|
||||||
# else find all users that start with user_begin
|
# 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()]
|
||||||
user for user in users_list if user_begin.lower() in user.lower()
|
|
||||||
]
|
|
||||||
|
|
||||||
return users[:25]
|
return users[:25]
|
||||||
|
|
||||||
@@ -165,15 +147,9 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
|||||||
list[str]: All users with submissions in the guild.
|
list[str]: All users with submissions in the guild.
|
||||||
"""
|
"""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
group_ids = select(CategoryGroup.GroupId).where(
|
group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id)
|
||||||
CategoryGroup.GuildId == guild_id
|
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids))
|
||||||
)
|
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
|
||||||
category_ids = select(Category.CategoryId).where(
|
|
||||||
Category.GroupId.in_(group_ids)
|
|
||||||
)
|
|
||||||
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 string empty, return all users
|
||||||
@@ -181,9 +157,7 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
|||||||
return users_list[:25]
|
return users_list[:25]
|
||||||
|
|
||||||
# else find all users that start with user_begin
|
# 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()]
|
||||||
user for user in users_list if user_begin.lower() in user.lower()
|
|
||||||
]
|
|
||||||
|
|
||||||
return users[:25]
|
return users[:25]
|
||||||
|
|
||||||
@@ -248,15 +222,11 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
|
|
||||||
# process data. Want each group sorted correctly and only top X results
|
# process data. Want each group sorted correctly and only top X results
|
||||||
processed_group = (
|
processed_group = (
|
||||||
group_df.sort_values("Score", ascending=category.IsAscending)
|
group_df.sort_values("Score", ascending=category.IsAscending).head(category.Size).reset_index()
|
||||||
.head(category.Size)
|
|
||||||
.reset_index()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# add each score to list
|
# add each score to list
|
||||||
for ind in range(
|
for ind in range(max_cat_size): # need to subtract to deal with category name string
|
||||||
max_cat_size
|
|
||||||
): # need to subtract to deal with category name string
|
|
||||||
if ind in processed_group.index:
|
if ind in processed_group.index:
|
||||||
username = processed_group["UserName"][ind]
|
username = processed_group["UserName"][ind]
|
||||||
score = processed_group["Score"][ind]
|
score = processed_group["Score"][ind]
|
||||||
@@ -357,9 +327,7 @@ def get_time_str(time_in: float) -> str:
|
|||||||
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(time_in))
|
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(time_in))
|
||||||
|
|
||||||
|
|
||||||
async def send_highscore_message(
|
async def send_highscore_message(session: Session, guild: nextcord.Guild, group: CategoryGroup) -> nextcord.Message:
|
||||||
session: Session, guild: nextcord.Guild, group: CategoryGroup
|
|
||||||
) -> nextcord.Message:
|
|
||||||
"""
|
"""
|
||||||
Function takes care of checking if a message exists for a group.
|
Function takes care of checking if a message exists for a group.
|
||||||
Creates and sends/edits the message.
|
Creates and sends/edits the message.
|
||||||
@@ -416,11 +384,7 @@ async def submit_score(
|
|||||||
else:
|
else:
|
||||||
score = float(score)
|
score = float(score)
|
||||||
|
|
||||||
stmt = (
|
stmt = select(Score).where(Score.UserName == username).where(Score.CategoryId == category_id)
|
||||||
select(Score)
|
|
||||||
.where(Score.UserName == username)
|
|
||||||
.where(Score.CategoryId == category_id)
|
|
||||||
)
|
|
||||||
existing_score = session.scalar(stmt)
|
existing_score = session.scalar(stmt)
|
||||||
|
|
||||||
if existing_score:
|
if existing_score:
|
||||||
@@ -446,9 +410,7 @@ def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
|||||||
config_str (str): Config name to add
|
config_str (str): Config name to add
|
||||||
"""
|
"""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
with open(
|
with open(f"example_config/{config_str}.json", encoding="utf-8") as file:
|
||||||
f"example_config/{config_str}.json", encoding="utf-8"
|
|
||||||
) as file:
|
|
||||||
config = json.load(file)
|
config = json.load(file)
|
||||||
|
|
||||||
for group_name, categorys in config["tables"].items():
|
for group_name, categorys in config["tables"].items():
|
||||||
|
|||||||
Reference in New Issue
Block a user