Compare commits
14
Commits
0ff1b07096
..
v4.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f735e6d846 | ||
|
|
9fbaf7bcf6 | ||
|
|
c25d354fc0 | ||
|
|
e5d90a71d9 | ||
|
|
74ce22dd26 | ||
|
|
170ce1cbfb | ||
|
|
e1b761e848 | ||
|
|
68592a7df8 | ||
|
|
b28938f66a | ||
|
|
3abbff13d5 | ||
|
|
f52b2fe49f | ||
|
|
24a9fa998a | ||
|
|
63db4c1dd2 | ||
|
|
8604ba2547 |
Vendored
+1
-1
@@ -10,7 +10,7 @@
|
|||||||
"ondelete"
|
"ondelete"
|
||||||
],
|
],
|
||||||
"python.analysis.diagnosticSeverityOverrides": {
|
"python.analysis.diagnosticSeverityOverrides": {
|
||||||
"reportOptionalMemberAccess": false,
|
"reportOptionalMemberAccess": "warning",
|
||||||
"reportArgumentType": "information",
|
"reportArgumentType": "information",
|
||||||
"reportAttributeAccessIssue": "warning"
|
"reportAttributeAccessIssue": "warning"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
FROM python:3.12.3-slim
|
FROM python:3.12.3-slim
|
||||||
|
|
||||||
# install uv
|
# install uv
|
||||||
COPY --from=ghcr.io/astral-sh/uv:0.6.2 /uv /uvx /bin/
|
COPY --from=ghcr.io/astral-sh/uv:0.6.5 /uv /uvx /bin/
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3
|
RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3
|
||||||
|
|
||||||
|
|||||||
+34
-141
@@ -7,9 +7,8 @@ from sqlalchemy.orm import Session
|
|||||||
from sqlmodel import col
|
from sqlmodel import col
|
||||||
|
|
||||||
from database.db import engine
|
from database.db import engine
|
||||||
from database.models import Category, CategoryGroup, Guild
|
from database.models import CategoryGroup, Guild
|
||||||
from utilities.logger import agon_logger
|
from utilities.utils import MAX_LINE_LENGTH, autofill_groups
|
||||||
from utilities.utils import MAX_LINE_LENGTH, autofill_categories, autofill_groups, send_highscore_message
|
|
||||||
|
|
||||||
|
|
||||||
class SetCog(commands.Cog, name="Set command."):
|
class SetCog(commands.Cog, name="Set command."):
|
||||||
@@ -22,116 +21,13 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
async def set(self, interaction: nextcord.Interaction) -> None:
|
async def set(self, interaction: nextcord.Interaction) -> None:
|
||||||
"""Parent slash command for setting settings. Never called."""
|
"""Parent slash command for setting settings. Never called."""
|
||||||
|
|
||||||
@set.subcommand("Commands for editing a category.")
|
@set.subcommand(description="Registers the channel for a Category Group's messages.")
|
||||||
async def category(self, interaction: nextcord.Interaction) -> None:
|
async def group_output_channel(
|
||||||
"""Parent slash subcommand for setting category settings. Never called."""
|
|
||||||
|
|
||||||
@category.subcommand(description="Update the number of entries to show for a category.", name="size")
|
|
||||||
async def category_size(
|
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
group_id: str = nextcord.SlashOption(
|
group_id: str = nextcord.SlashOption(
|
||||||
name="group", description="Category Group that Category is in.", required=True
|
name="group", description="Category Group to assign to channel.", required=True
|
||||||
),
|
),
|
||||||
category_id: str = nextcord.SlashOption(
|
|
||||||
name="category", description="Category to update size of.", required=True
|
|
||||||
),
|
|
||||||
size: int = nextcord.SlashOption(description="Number of entries to show for the category.", required=True),
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Command to update a category's size.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
||||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
|
||||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
|
||||||
size (int): Size to set. Is SlashOption.
|
|
||||||
"""
|
|
||||||
stmt = select(Category).where(col(CategoryGroup.id == group_id)).where(col(Category.id) == int(category_id))
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
|
||||||
category = session.scalar(stmt)
|
|
||||||
if category is None:
|
|
||||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
|
||||||
return
|
|
||||||
category.size = size
|
|
||||||
# session.add(category) test if this is needed. SQLAlchemy can do the update without adding.
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
# Use the relationship to get group category is in.
|
|
||||||
group = category.category_group
|
|
||||||
if group is None:
|
|
||||||
await interaction.response.send_message(
|
|
||||||
f"An error with {category.name} and group relationship. Contact developer. Size was still updated.",
|
|
||||||
ephemeral=True,
|
|
||||||
)
|
|
||||||
agon_logger.error(f"{category.name}:{category.id} group relationship was None.")
|
|
||||||
return
|
|
||||||
|
|
||||||
await send_highscore_message(session, interaction.guild, group)
|
|
||||||
await interaction.response.send_message(f"{category.name} size has been updated to {size}.", ephemeral=True)
|
|
||||||
|
|
||||||
@category.subcommand(description="Update the is_ascending value for a category.")
|
|
||||||
async def is_ascending(
|
|
||||||
self,
|
|
||||||
interaction: nextcord.Interaction,
|
|
||||||
group_id: str = nextcord.SlashOption(
|
|
||||||
name="group", description="Category Group that Category is in.", required=True
|
|
||||||
),
|
|
||||||
category_id: str = nextcord.SlashOption(
|
|
||||||
name="category", description="Category to update is_ascending of.", required=True
|
|
||||||
),
|
|
||||||
ascending: bool = nextcord.SlashOption( # noqa: FBT001
|
|
||||||
description="Whether the scores are sorted ascending or not.", required=True
|
|
||||||
),
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Command to update a category's is_ascending boolean.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
||||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
|
||||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
|
||||||
ascending (bool): Boolean to set. Determines whether scores are sorted ascending or not. Is SlashOption.
|
|
||||||
"""
|
|
||||||
stmt = select(Category).where(col(CategoryGroup.id == group_id)).where(col(Category.id) == int(category_id))
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
|
||||||
category = session.scalar(stmt)
|
|
||||||
if category is None:
|
|
||||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
|
||||||
return
|
|
||||||
category.is_ascending = ascending
|
|
||||||
# session.add(category) test if this is needed. SQLAlchemy can do the update without adding.
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
# Use the relationship to get group category is in.
|
|
||||||
group = category.category_group
|
|
||||||
if group is None:
|
|
||||||
await interaction.response.send_message(
|
|
||||||
(
|
|
||||||
f"An error with {category.name} and group relationship. Contact developer. "
|
|
||||||
"Is_ascending was still updated."
|
|
||||||
),
|
|
||||||
ephemeral=True,
|
|
||||||
)
|
|
||||||
agon_logger.error(f"{category.name}:{category.id} group relationship was None.")
|
|
||||||
return
|
|
||||||
|
|
||||||
await send_highscore_message(session, interaction.guild, group)
|
|
||||||
await interaction.response.send_message(
|
|
||||||
f"{category.name} is_ascending has been updated to {ascending}.", ephemeral=True
|
|
||||||
)
|
|
||||||
|
|
||||||
@set.subcommand(description="Commands for editing a group.")
|
|
||||||
async def group(self, interaction: nextcord.Interaction) -> None:
|
|
||||||
"""Parent slash subcommand for setting group settings. Never called."""
|
|
||||||
|
|
||||||
@group.subcommand(description="Registers the channel for a Group's messages.")
|
|
||||||
async def output_channel(
|
|
||||||
self,
|
|
||||||
interaction: nextcord.Interaction,
|
|
||||||
group_id: str = nextcord.SlashOption(name="group", description="Group to assign to channel.", required=True),
|
|
||||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
@@ -145,7 +41,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||||
channel (nextcord.abc.GuildChannel, optional): Channel to register.
|
channel (nextcord.abc.GuildChannel, optional): Channel to register
|
||||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||||
"""
|
"""
|
||||||
channel_id = interaction.channel.id if not channel else channel.id
|
channel_id = interaction.channel.id if not channel else channel.id
|
||||||
@@ -156,18 +52,22 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||||
.where(col(CategoryGroup.id) == int(group_id))
|
.where(col(CategoryGroup.id) == int(group_id))
|
||||||
)
|
)
|
||||||
group = session.scalar(stmt)
|
if (group := session.scalar(stmt)) is None:
|
||||||
group.ChannelId = channel_id
|
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||||
|
return
|
||||||
|
group.channel_id = channel_id
|
||||||
session.commit()
|
session.commit()
|
||||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||||
|
|
||||||
@group.subcommand(
|
@set.subcommand(
|
||||||
description="Set character length for a category. Can cut off username/score. Affects all categories."
|
description="Set character length for a category. Can cut off username/score. Affects all categories."
|
||||||
)
|
)
|
||||||
async def pad_length(
|
async def pad_length(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
group_id: str = nextcord.SlashOption(name="group", description="Group to assign pad length to.", required=True),
|
group_id: str = nextcord.SlashOption(
|
||||||
|
name="group", description="Category Group to assign pad length to.", required=True
|
||||||
|
),
|
||||||
length: int = nextcord.SlashOption(
|
length: int = nextcord.SlashOption(
|
||||||
description="Number of characters alloted to a category.",
|
description="Number of characters alloted to a category.",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -190,14 +90,17 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||||
.where(col(CategoryGroup.id) == int(group_id))
|
.where(col(CategoryGroup.id) == int(group_id))
|
||||||
)
|
)
|
||||||
group = session.scalar(stmt)
|
if (group := session.scalar(stmt)) is None:
|
||||||
group.PadLength = length
|
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
group.pad_length = length
|
||||||
session.commit()
|
session.commit()
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
f"Category pad length set to {length} for {group.name}", ephemeral=True
|
f"Category pad length set to {length} for {group.name}", ephemeral=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@group.subcommand(
|
@set.subcommand(
|
||||||
description="Registers the channel for submission messages. Currently this information is deprecated."
|
description="Registers the channel for submission messages. Currently this information is deprecated."
|
||||||
)
|
)
|
||||||
async def submission_channel(
|
async def submission_channel(
|
||||||
@@ -222,12 +125,14 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Guild).where(col(Guild.id) == interaction.guild_id)
|
stmt = select(Guild).where(col(Guild.id) == interaction.guild_id)
|
||||||
guild = session.scalar(stmt)
|
if (guild := session.scalar(stmt)) is None:
|
||||||
|
await interaction.response.send_message("Guild was not found.", ephemeral=True)
|
||||||
|
return
|
||||||
guild.submission_channel = channel_id
|
guild.submission_channel = channel_id
|
||||||
session.commit()
|
session.commit()
|
||||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||||
|
|
||||||
@group.subcommand(description="Set username length for a Group of Categories.")
|
@set.subcommand(description="Set username length for a Group of Categories.")
|
||||||
async def username_length(
|
async def username_length(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
@@ -252,8 +157,11 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||||
.where(col(CategoryGroup.id) == int(group_id))
|
.where(col(CategoryGroup.id) == int(group_id))
|
||||||
)
|
)
|
||||||
group = session.scalar(stmt)
|
if (group := session.scalar(stmt)) is None:
|
||||||
group.UsernameLength = length
|
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
group.username_length = length
|
||||||
session.commit()
|
session.commit()
|
||||||
await interaction.response.send_message(f"Username length set to {length}.", ephemeral=True)
|
await interaction.response.send_message(f"Username length set to {length}.", ephemeral=True)
|
||||||
|
|
||||||
@@ -280,29 +188,14 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Guild).where(col(Guild.id) == interaction.guild_id)
|
stmt = select(Guild).where(col(Guild.id) == interaction.guild_id)
|
||||||
guild = session.scalar(stmt)
|
if (guild := session.scalar(stmt)) is None:
|
||||||
guild.VerificationChannel = channel_id
|
await interaction.response.send_message("Guild was not found.", ephemeral=True)
|
||||||
|
return
|
||||||
|
guild.verification_channel = channel_id
|
||||||
session.commit()
|
session.commit()
|
||||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||||
|
|
||||||
@category_size.on_autocomplete("category_id")
|
@group_output_channel.on_autocomplete("group_id")
|
||||||
@is_ascending.on_autocomplete("category_id")
|
|
||||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
|
||||||
"""
|
|
||||||
Autocomplete function for category names.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
||||||
category_id (str): String to be autocompleted with Category name.
|
|
||||||
group_id (str): Group to find Category from.
|
|
||||||
"""
|
|
||||||
await interaction.response.send_autocomplete(
|
|
||||||
autofill_categories(interaction.guild_id, int(group_id), category_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
@category_size.on_autocomplete("group_id")
|
|
||||||
@output_channel.on_autocomplete("group_id")
|
|
||||||
@is_ascending.on_autocomplete("group_id")
|
|
||||||
@pad_length.on_autocomplete("group_id")
|
@pad_length.on_autocomplete("group_id")
|
||||||
@username_length.on_autocomplete("group_id")
|
@username_length.on_autocomplete("group_id")
|
||||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||||
|
|||||||
+11
-14
@@ -11,7 +11,7 @@ from sqlmodel import col
|
|||||||
from cogs.submission.verification_view import VerificationView
|
from cogs.submission.verification_view import VerificationView
|
||||||
from database.db import engine
|
from database.db import engine
|
||||||
from database.models import Category, CategoryGroup, Guild, Submission
|
from database.models import Category, CategoryGroup, Guild, Submission
|
||||||
from main import agon_logger
|
from main import logger
|
||||||
from utilities.utils import autofill_categories, autofill_groups, submit_score
|
from utilities.utils import autofill_categories, autofill_groups, submit_score
|
||||||
|
|
||||||
|
|
||||||
@@ -64,10 +64,7 @@ class SubmissionCog(commands.Cog):
|
|||||||
.where(col(Category.group_id) == int(group_id))
|
.where(col(Category.group_id) == int(group_id))
|
||||||
.where(col(Category.id) == int(category_id))
|
.where(col(Category.id) == int(category_id))
|
||||||
)
|
)
|
||||||
|
if (category := session.scalar(stmt)) is None:
|
||||||
category: Category | None = session.scalar(stmt)
|
|
||||||
|
|
||||||
if category is None:
|
|
||||||
await interaction.response.send_message("Category not found.", ephemeral=True)
|
await interaction.response.send_message("Category not found.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -79,10 +76,13 @@ class SubmissionCog(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# check with regex if score is in correct format
|
# check with regex if score is in correct format
|
||||||
verified_score = await self.verify_score(interaction, score, is_time_record=category.is_time_record)
|
|
||||||
|
|
||||||
# check if verify_score was successful. It replies with corrections required itself.
|
# check if verify_score was successful. It replies with corrections required itself.
|
||||||
if verified_score is None:
|
if (
|
||||||
|
verified_score := await self.verify_score(interaction, score, is_time_record=category.is_time_record)
|
||||||
|
) is None:
|
||||||
|
# This response message will be filled out better once command is split up to
|
||||||
|
# know which type it expects...
|
||||||
|
await interaction.response.send_message("Format was incorrect.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create submission verification request or submit score if verification not needed.
|
# Create submission verification request or submit score if verification not needed.
|
||||||
@@ -92,23 +92,20 @@ class SubmissionCog(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
stmt = select(col(Guild.verification_channel)).where(col(Guild.id) == interaction.guild_id)
|
stmt = select(col(Guild.verification_channel)).where(col(Guild.id) == interaction.guild_id)
|
||||||
verification_channel_id: int | None = session.scalar(stmt)
|
|
||||||
|
|
||||||
if verification_channel_id is None:
|
if (verification_channel_id := session.scalar(stmt)) is None:
|
||||||
error_response = "No verification channel was registered. Contact server admins."
|
error_response = "No verification channel was registered. Contact server admins."
|
||||||
await interaction.response.send_message(error_response, ephemeral=True)
|
await interaction.response.send_message(error_response, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
channel = interaction.guild.get_channel(verification_channel_id)
|
if (channel := interaction.guild.get_channel(verification_channel_id)) is None:
|
||||||
|
|
||||||
if channel is None:
|
|
||||||
error_response = "Registered Verification channel does not exist. Contact server admins."
|
error_response = "Registered Verification channel does not exist. Contact server admins."
|
||||||
await interaction.response.send_message(error_response, ephemeral=True)
|
await interaction.response.send_message(error_response, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not isinstance(channel, nextcord.TextChannel):
|
if not isinstance(channel, nextcord.TextChannel):
|
||||||
await interaction.response.send_message("An error happened with submission.")
|
await interaction.response.send_message("An error happened with submission.")
|
||||||
agon_logger.error(
|
logger.error(
|
||||||
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
|
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -26,10 +26,9 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
|||||||
"""
|
"""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Guild).where(col(Guild.id == guild.id))
|
stmt = select(Guild).where(col(Guild.id == guild.id))
|
||||||
guild_data = session.scalar(stmt)
|
|
||||||
|
|
||||||
# just in case check if the guild already exists
|
# just in case check if the guild already exists
|
||||||
if guild_data is None:
|
if (guild_data := session.scalar(stmt)) is None:
|
||||||
new_guild = Guild(id=guild.id, name=guild.name)
|
new_guild = Guild(id=guild.id, name=guild.name)
|
||||||
session.add(new_guild)
|
session.add(new_guild)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class GuildData(commands.Cog, name="Guild Data"):
|
|||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
for guild in self.bot.guilds:
|
for guild in self.bot.guilds:
|
||||||
# update given guild name for guild id
|
# update given guild name for guild id
|
||||||
stmt = select(Guild).where(col(Guild.id == guild.id))
|
stmt = select(Guild).where(col(Guild.id) == guild.id)
|
||||||
guild_data = session.scalar(stmt)
|
guild_data = session.scalar(stmt)
|
||||||
|
|
||||||
# just in case checking if the guild doesn't exist.
|
# just in case checking if the guild doesn't exist.
|
||||||
@@ -39,6 +39,6 @@ class GuildData(commands.Cog, name="Guild Data"):
|
|||||||
new_guild = Guild(id=guild.id, name=guild.name)
|
new_guild = Guild(id=guild.id, name=guild.name)
|
||||||
session.add(new_guild)
|
session.add(new_guild)
|
||||||
else:
|
else:
|
||||||
guild_data.GuildName = guild.name
|
guild_data.name = guild.name
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|||||||
@@ -39,9 +39,7 @@ class VerificationView(nextcord.ui.View):
|
|||||||
.where(col(Submission.message_id) == interaction.message.id)
|
.where(col(Submission.message_id) == interaction.message.id)
|
||||||
)
|
)
|
||||||
|
|
||||||
submission = session.scalar(stmt)
|
if (submission := session.scalar(stmt)) is None:
|
||||||
|
|
||||||
if submission is None:
|
|
||||||
await interaction.response.send_message("Could not find submission data in database.", ephemeral=True)
|
await interaction.response.send_message("Could not find submission data in database.", ephemeral=True)
|
||||||
await interaction.message.delete()
|
await interaction.message.delete()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import nextcord
|
|||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from utilities import config
|
from utilities import config
|
||||||
from utilities.logger import agon_logger
|
|
||||||
|
|
||||||
nextcord_logger = logging.getLogger("nextcord")
|
nextcord_logger = logging.getLogger("nextcord")
|
||||||
nextcord_logger.setLevel(logging.DEBUG)
|
nextcord_logger.setLevel(logging.DEBUG)
|
||||||
@@ -16,12 +15,18 @@ nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8"
|
|||||||
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
||||||
nextcord_logger.addHandler(nextcord_handler)
|
nextcord_logger.addHandler(nextcord_handler)
|
||||||
|
|
||||||
|
logger = logging.getLogger("default")
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
handler = logging.StreamHandler(sys.stdout)
|
||||||
|
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""Main function for bot."""
|
"""Main function for bot."""
|
||||||
min_python_version = (3, 12)
|
min_python_version = (3, 12)
|
||||||
if sys.version_info < min_python_version:
|
if sys.version_info < min_python_version:
|
||||||
agon_logger.error("ERROR: Python version must be >= 3.12")
|
logger.error("ERROR: Python version must be >= 3.12")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
|
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
|
||||||
@@ -41,9 +46,9 @@ def main() -> None:
|
|||||||
async def on_ready() -> None:
|
async def on_ready() -> None:
|
||||||
"""When Discord is connected."""
|
"""When Discord is connected."""
|
||||||
if bot.user is None:
|
if bot.user is None:
|
||||||
agon_logger.error("Discord connection failed.")
|
logger.error("Discord connection failed.")
|
||||||
return
|
return
|
||||||
agon_logger.info("%s has connected to Discord!", bot.user.name)
|
logger.info("%s has connected to Discord!", bot.user.name)
|
||||||
|
|
||||||
# Run Discord bot
|
# Run Discord bot
|
||||||
bot.run(config.DISCORD_TOKEN)
|
bot.run(config.DISCORD_TOKEN)
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
"""Creates logger for Agon bot."""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
|
|
||||||
agon_logger = logging.getLogger("default")
|
|
||||||
agon_logger.setLevel(logging.INFO)
|
|
||||||
handler = logging.StreamHandler(sys.stdout)
|
|
||||||
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
|
||||||
agon_logger.addHandler(handler)
|
|
||||||
+3
-3
@@ -64,7 +64,7 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
|||||||
"""
|
"""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# Select all groups in guild.
|
# Select all groups in guild.
|
||||||
stmt = select(CategoryGroup).wherecol((CategoryGroup.guild_id) == guild_id)
|
stmt = select(CategoryGroup).where(col(CategoryGroup.guild_id) == 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.name: str(group.id) for group in session.scalars(stmt)}
|
group_dict: dict[str, str] = {group.name: str(group.id) for group in session.scalars(stmt)}
|
||||||
@@ -347,7 +347,7 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
|
|||||||
if group.message_id is None:
|
if group.message_id is None:
|
||||||
# message doesn't exist.
|
# message doesn't exist.
|
||||||
message: nextcord.Message = await channel.send(highscore_string)
|
message: nextcord.Message = await channel.send(highscore_string)
|
||||||
group.MessageId = message.id
|
group.message_id = message.id
|
||||||
session.commit()
|
session.commit()
|
||||||
else:
|
else:
|
||||||
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
||||||
@@ -390,7 +390,7 @@ async def submit_score(
|
|||||||
existing_score = session.scalar(stmt)
|
existing_score = session.scalar(stmt)
|
||||||
|
|
||||||
if existing_score:
|
if existing_score:
|
||||||
existing_score.Score = score_f
|
existing_score.score = score_f
|
||||||
else:
|
else:
|
||||||
score_obj = Score(username=username, score=score_f, category_id=category_id)
|
score_obj = Score(username=username, score=score_f, category_id=category_id)
|
||||||
session.add(score_obj)
|
session.add(score_obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user