Use walrus operator when assigning and checking for None.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user