Skip to content

Commit

Permalink
Invalidate guild config cache if guild is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Dec 28, 2023
1 parent 231a402 commit 5023b44
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions bot/cogs/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from rodhaj import TRANSPROGRAMMER_SERVER_ID

STAFF_ROLE = 1184257456419913798
MOD_ROLE = 1 # later this is the correct one
TICKET_CHANNEL = 1183305410304806922 # maybe fetch it from the DB? probably not needed


Expand Down Expand Up @@ -258,10 +257,10 @@ async def close(self, ctx: RoboContext) -> None:
WHERE thread_id = $1 AND owner_id = $2;
"""
get_owner_id_query = """
SELECT owner_id
FROM tickets
WHERE thread_id = $1 AND location_id = $2;
"""
SELECT owner_id
FROM tickets
WHERE thread_id = $1 AND location_id = $2;
"""

async with self.pool.acquire() as conn:
if await self.can_close_ticket(ctx, conn):
Expand All @@ -283,6 +282,13 @@ async def close(self, ctx: RoboContext) -> None:
get_partial_ticket.cache_invalidate(self.bot, owner_id, self.pool)
await self.notify_finished_ticket(ctx, owner_id)

# As the guild has an entry in the cache,
# we need to invalidate it if a guild goes
@commands.Cog.listener()
async def on_guild_remove(self, guild: discord.Guild) -> None:
dispatcher = GuildWebhookDispatcher(self.bot, guild.id)
dispatcher.get_config.cache_invalidate()

@commands.Cog.listener()
async def on_ticket_create(
self,
Expand Down Expand Up @@ -311,7 +317,10 @@ async def on_ticket_close(
webhook = await self.obtain_webhook(guild.id)

if webhook is not None:
embed = LoggingEmbed(title="\U0001f512 Ticket Closed")
embed = LoggingEmbed(
title="\U0001f512 Ticket Closed",
color=discord.Color.from_rgb(194, 163, 255),
)
embed.description = f"The ticket has closed at {format_dt(utcnow())}"
if author is not None:
embed.add_field(name="Closed By", value=author.mention)
Expand Down

0 comments on commit 5023b44

Please sign in to comment.