Use the walrus operator when assigning and checking for None.
This commit is contained in:
+12
-35
@@ -50,8 +50,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
category = session.scalar(stmt)
|
||||
if category is None:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.size = size
|
||||
@@ -59,13 +58,11 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
group = category.category_group
|
||||
if group is None:
|
||||
if (group := category.category_group) is None:
|
||||
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
group = session.scalar(stmt)
|
||||
if group is None:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
@@ -98,8 +95,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
category = session.scalar(stmt)
|
||||
if category is None:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.is_ascending = ascending
|
||||
@@ -107,13 +103,11 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
group = category.category_group
|
||||
if group is None:
|
||||
if (group := category.category_group) is None:
|
||||
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
group = session.scalar(stmt)
|
||||
if group is None:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
@@ -148,25 +142,13 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
category = session.scalar(stmt)
|
||||
if category is None:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.is_validated = validated
|
||||
# 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:
|
||||
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
group = session.scalar(stmt)
|
||||
if group is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"{category.name} is_validated has been updated to {validated}.", ephemeral=True
|
||||
)
|
||||
@@ -195,8 +177,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
category = session.scalar(stmt)
|
||||
if category is None:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
old_name = category.name
|
||||
@@ -205,13 +186,11 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
group = category.category_group
|
||||
if group is None:
|
||||
if (group := category.category_group) is None:
|
||||
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
group = session.scalar(stmt)
|
||||
if group is None:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
@@ -240,8 +219,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
|
||||
|
||||
with Session(engine) as session:
|
||||
group = session.scalar(stmt)
|
||||
if group is None:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
old_name = group.name
|
||||
@@ -315,8 +293,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
if group is None:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
group.PadLength = length
|
||||
|
||||
Reference in New Issue
Block a user