Merge branch 'main' of https://gitea.cheezers.org/imcompiling/agon
build_latest / build (push) Successful in 37s

This commit is contained in:
2025-03-21 10:45:04 -04:00
6 changed files with 28 additions and 15 deletions
+1 -1
View File
@@ -99,7 +99,7 @@ class CreateCog(commands.Cog, name="Create Cog"):
min_value=1, min_value=1,
max_value=30, max_value=30,
), ),
channel: nextcord.TextChannel | None = nextcord.SlashOption( channel: nextcord.TextChannel | nextcord.Thread | None = nextcord.SlashOption(
description="Channel to post Group in. If left empty, defaults to current channel.", description="Channel to post Group in. If left empty, defaults to current channel.",
required=False, required=False,
default=None, default=None,
+2 -2
View File
@@ -37,7 +37,7 @@ class DeleteCog(commands.Cog, name="Delete Cog"):
async def channel_messages( async def channel_messages(
self, self,
interaction: nextcord.Interaction, interaction: nextcord.Interaction,
channel: nextcord.TextChannel | None = nextcord.SlashOption( channel: nextcord.TextChannel | nextcord.Thread | None = nextcord.SlashOption(
description="Channel to clear of messages.", description="Channel to clear of messages.",
required=False, required=False,
default=None, default=None,
@@ -54,7 +54,7 @@ class DeleteCog(commands.Cog, name="Delete Cog"):
Is a SlashOption. Limited to text channels. Defaults to None. Is a SlashOption. Limited to text channels. Defaults to None.
""" """
if not channel: if not channel:
if isinstance(interaction.channel, nextcord.TextChannel): if isinstance(interaction.channel, nextcord.TextChannel | nextcord.Thread):
channel = interaction.channel channel = interaction.channel
else: else:
# This should never happen. # This should never happen.
+10 -3
View File
@@ -251,6 +251,10 @@ class SetCog(commands.Cog, name="Set command."):
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.
""" """
if interaction.guild is None or interaction.channel is None:
agon_logger.warning("Set command was called with an interaction that had no guild or channel.")
return
channel_id = interaction.channel.id if not channel else channel.id channel_id = interaction.channel.id if not channel else channel.id
with Session(engine) as session: with Session(engine) as session:
@@ -262,11 +266,14 @@ class SetCog(commands.Cog, name="Set command."):
if (group := session.scalar(stmt)) is None: if (group := session.scalar(stmt)) is None:
await interaction.response.send_message("Group or Category was not found.", ephemeral=True) await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
return return
old_channel_id = group.channel_id
group.channel_id = channel_id group.channel_id = channel_id
session.commit() session.commit()
# TODO(imcompiling): delete the message and call send_highscore_message to send a new one. Bug needs fixed
# first. old_channel = interaction.guild.get_channel(old_channel_id)
# 082 if old_channel and isinstance(old_channel, nextcord.TextChannel | nextcord.Thread) and group.message_id:
await old_channel.get_partial_message(group.message_id).delete()
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True) await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
@group.subcommand( @group.subcommand(
+1 -1
View File
@@ -101,7 +101,7 @@ class SubmissionCog(commands.Cog):
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 | nextcord.Thread):
await interaction.response.send_message("An error happened with submission.") await interaction.response.send_message("An error happened with submission.")
agon_logger.error( agon_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
+1 -1
View File
@@ -43,7 +43,7 @@ class DeleteConfirmView(nextcord.ui.Modal):
session.delete(group) session.delete(group)
# delete the message related to group # delete the message related to group
channel = interaction.guild.get_channel(group.channel_id) channel = interaction.guild.get_channel(group.channel_id)
if not isinstance(channel, nextcord.TextChannel): if not isinstance(channel, nextcord.TextChannel | nextcord.Thread):
return return
message: nextcord.Message = await channel.fetch_message(group.message_id) message: nextcord.Message = await channel.fetch_message(group.message_id)
await message.delete() await message.delete()
+13 -7
View File
@@ -342,11 +342,13 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
group (CategoryGroup): group to post to the message. group (CategoryGroup): group to post to the message.
""" """
highscore_string = format_highscore_message(session, group) highscore_string = format_highscore_message(session, group)
channel = guild.get_channel(group.channel_id) if (channel := guild.get_channel(group.channel_id)) is None:
agon_logger.error("Channel id %s in guild %s does not exist.", group.channel_id, guild.id)
return
if not isinstance(channel, nextcord.TextChannel): if not isinstance(channel, nextcord.TextChannel | nextcord.Thread):
agon_logger.error( agon_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 or Thread.", channel.id, channel.guild.id
) )
return return
@@ -356,10 +358,14 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
group.message_id = message.id group.message_id = message.id
session.commit() session.commit()
else: else:
# TODO(imcompiling): check what happens when message is deleted. try:
# https://gitea.cheezers.org/imcompiling/agon/issues/83 message: nextcord.Message = await channel.fetch_message(group.message_id)
message: nextcord.Message = await channel.fetch_message(group.message_id) await message.edit(content=highscore_string)
await message.edit(content=highscore_string) except nextcord.NotFound:
# Message was deleted on discord's side.
message: nextcord.Message = await channel.send(highscore_string)
group.message_id = message.id
session.commit()
return return