Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12893288f8 |
@@ -251,10 +251,6 @@ 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:
|
||||||
@@ -266,14 +262,11 @@ 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
|
||||||
old_channel = interaction.guild.get_channel(old_channel_id)
|
# first.
|
||||||
if old_channel and isinstance(old_channel, nextcord.TextChannel | nextcord.Thread) and group.message_id:
|
# 082
|
||||||
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(
|
||||||
|
|||||||
+5
-9
@@ -342,7 +342,7 @@ 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)
|
||||||
if (channel := guild.get_channel(group.channel_id)) is None:
|
if (channel := guild.get_channel_or_thread(group.channel_id)) is None:
|
||||||
agon_logger.error("Channel id %s in guild %s does not exist.", group.channel_id, guild.id)
|
agon_logger.error("Channel id %s in guild %s does not exist.", group.channel_id, guild.id)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -358,14 +358,10 @@ 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:
|
||||||
try:
|
# TODO(imcompiling): check what happens when message is deleted.
|
||||||
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
# https://gitea.cheezers.org/imcompiling/agon/issues/83
|
||||||
await message.edit(content=highscore_string)
|
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
||||||
except nextcord.NotFound:
|
await message.edit(content=highscore_string)
|
||||||
# Message was deleted on discord's side.
|
|
||||||
message: nextcord.Message = await channel.send(highscore_string)
|
|
||||||
group.message_id = message.id
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user