diff --git a/Discord/clients.py b/Discord/clients.py index 8ea99b4b22..4fa970ac75 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -371,7 +371,8 @@ async def initialize_database(self): """ CREATE TABLE IF NOT EXISTS meta.restart_channels ( channel_id BIGINT PRIMARY KEY, - player_text_channel_id BIGINT + player_text_channel_id BIGINT, + restart_message_id BIGINT ) """ ) @@ -501,14 +502,20 @@ async def initialize_constant_objects(self): async def startup_tasks(self): await self.wait_until_ready() print(f"Started up Discord {self.user} ({self.user.id})") - if restart_channel_id := await self.db.fetchval( + if (record := await self.db.fetchrow( """ DELETE FROM meta.restart_channels WHERE player_text_channel_id IS NULL - RETURNING channel_id - """ - ): - await self.send_embed(self.get_channel(restart_channel_id), ":thumbsup::skin-tone-2: Restarted") + RETURNING * + """ + )) and (restart_channel := self.get_channel(record["channel_id"])) and (restart_message_id := record["restart_message_id"]): + try: + restart_message = await restart_channel.fetch_message(restart_message_id) + embed = restart_message.embeds[0] + embed.description += "\n:thumbsup::skin-tone-2: Restarted" + await restart_message.edit(embed = embed) + except discord.NotFound: + await self.send_embed(restart_channel, ":thumbsup::skin-tone-2: Restarted") if audio_cog := self.get_cog("Audio"): for record in await self.db.fetch("DELETE FROM meta.restart_channels RETURNING *"): if text_channel := self.get_channel(record["player_text_channel_id"]): @@ -812,7 +819,7 @@ async def update_all_listing_stats(self): for site in self.listing_sites: await self.update_listing_stats(site) - async def restart_tasks(self, channel_id): + async def restart_tasks(self, channel_id, message_id): # Increment restarts counter await self.db.execute( """ @@ -825,11 +832,11 @@ async def restart_tasks(self, channel_id): # Save restart text channel + voice channels await self.db.execute( """ - INSERT INTO meta.restart_channels (channel_id) - VALUES ($1) + INSERT INTO meta.restart_channels (channel_id, restart_message_id) + VALUES ($1, $2) ON CONFLICT (channel_id) DO NOTHING """, - channel_id + channel_id, message_id ) if audio_cog := self.get_cog("Audio"): for voice_client in self.voice_clients: diff --git a/Discord/cogs/meta.py b/Discord/cogs/meta.py index c0f394b53b..0f893272c0 100644 --- a/Discord/cogs/meta.py +++ b/Discord/cogs/meta.py @@ -483,9 +483,9 @@ async def update_listing_stats(self, ctx, site = None): @commands.is_owner() async def restart(self, ctx): '''Restart me''' - await ctx.embed_send(":ok_hand::skin-tone-2: Restarting...") + restart_message = await ctx.embed_send(":ok_hand::skin-tone-2: Restarting...") print("Shutting down Discord Harmonbot...") - await ctx.bot.restart_tasks(ctx.channel.id) + await ctx.bot.restart_tasks(ctx.channel.id, restart_message.id) await ctx.bot.logout() @commands.command(aliases = ["crash", "panic"])