Skip to content

Commit d192c7d

Browse files
committed
Update channel sync to keep Channel.deleted attribute up to date
1 parent ef0c908 commit d192c7d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

metricity/exts/event_listeners/guild_listeners.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,22 @@ async def sync_channels(self, guild: discord.Guild) -> None:
153153
name=channel.name,
154154
category_id=category_id,
155155
is_staff=is_staff,
156+
deleted=False,
156157
))
157158

158159
await sess.commit()
159160

160-
log.info("Channel synchronisation process complete, synchronising threads")
161+
log.info("Channel synchronisation process complete, synchronising deleted channels")
162+
163+
async with async_session() as sess:
164+
await sess.execute(
165+
update(models.Channel)
166+
.where(~models.Channel.id.in_([str(channel.id) for channel in guild.channels]))
167+
.values(deleted=True),
168+
)
169+
await sess.commit()
170+
171+
log.info("Deleted channel synchronisation process complete, synchronising threads")
161172

162173
async with async_session() as sess:
163174
for thread in guild.threads:
@@ -189,6 +200,14 @@ async def on_guild_channel_create(self, channel: discord.abc.GuildChannel) -> No
189200

190201
await self.sync_channels(channel.guild)
191202

203+
@commands.Cog.listener()
204+
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel) -> None:
205+
"""Set the deleted flag to true when a channel is deleted."""
206+
if channel.guild.id != BotConfig.guild_id:
207+
return
208+
209+
await self.sync_channels(channel.guild)
210+
192211
@commands.Cog.listener()
193212
async def on_guild_channel_update(
194213
self,

0 commit comments

Comments
 (0)