Compare commits

...
Author SHA1 Message Date
imcompiling af7518c1a2 Delete old group message when changing output channel.
build_develop / build (push) Successful in 29s
2025-03-20 10:55:48 -04:00
imcompiling 5be029fb57 Catch when the message has been deleted without entry deletion in my database. 2025-03-20 10:42:24 -04:00
imcompiling d82999b141 Check for channel being None. Allow groups to be posted in threads. 2025-03-20 09:50:31 -04:00
imcompiling 1ffb7fa9a7 Correct database ignore.
build_develop / build (push) Successful in 18s
build_latest / build (push) Successful in 18s
build_release / build (push) Successful in 19s
2025-03-19 09:51:38 -04:00
imcompiling 2566bee0ce Use home dir.
build_develop / build (push) Successful in 36s
2025-03-19 09:37:32 -04:00
4 changed files with 26 additions and 13 deletions
+1 -1
View File
@@ -135,4 +135,4 @@ deleted_backups/
highscores_data/ highscores_data/
TODO.txt TODO.txt
sql_tester.py sql_tester.py
database /database
+2 -2
View File
@@ -6,10 +6,10 @@ COPY --from=ghcr.io/astral-sh/uv:0.6.6 /uv /uvx /bin/
RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3 RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3
# Copy project to image # Copy project to image
ADD . /agon ADD . /home
# Sync the project into a new environment, using the frozen lockfile # Sync the project into a new environment, using the frozen lockfile
WORKDIR /agon WORKDIR /home
RUN uv sync --frozen --no-dev RUN uv sync --frozen --no-dev
CMD ["uv", "run", "--frozen", "--no-dev", "-m", "agon"] CMD ["uv", "run", "--frozen", "--no-dev", "-m", "agon"]
+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(
+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) or not isinstance(channel, 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