Compare commits

..
6 Commits
5 changed files with 15 additions and 21 deletions
+9 -12
View File
@@ -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,16 +92,13 @@ 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
+1 -2
View File
@@ -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:
+2 -2
View File
@@ -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()
+1 -3
View File
@@ -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
+2 -2
View File
@@ -65,7 +65,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)}
@@ -353,7 +353,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:
# TODO(imcompiling): check what happens when message is deleted. # TODO(imcompiling): check what happens when message is deleted.