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.id) == int(category_id))
|
||||
)
|
||||
|
||||
category: Category | None = session.scalar(stmt)
|
||||
|
||||
if category is None:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
@@ -79,10 +76,13 @@ class SubmissionCog(commands.Cog):
|
||||
return
|
||||
|
||||
# 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.
|
||||
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
|
||||
|
||||
# Create submission verification request or submit score if verification not needed.
|
||||
@@ -92,16 +92,13 @@ class SubmissionCog(commands.Cog):
|
||||
return
|
||||
|
||||
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."
|
||||
await interaction.response.send_message(error_response, ephemeral=True)
|
||||
return
|
||||
|
||||
channel = interaction.guild.get_channel(verification_channel_id)
|
||||
|
||||
if channel is None:
|
||||
if (channel := interaction.guild.get_channel(verification_channel_id)) is None:
|
||||
error_response = "Registered Verification channel does not exist. Contact server admins."
|
||||
await interaction.response.send_message(error_response, ephemeral=True)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user