fix(shard): 🐛 Channel webhooks suddenly stopping working.

This commit is contained in:
2025-03-16 00:49:34 -03:00
parent 0067481528
commit f0437f30ae
3 changed files with 51 additions and 21 deletions
+1 -1
View File
@@ -194,7 +194,7 @@ class Payphone(commands.AutoShardedBot):
return prefix return prefix
def clean_message(self, message: discord.Message, call) -> str: def clean_message(self, message: discord.Message) -> str:
"""Cleans a message. """Cleans a message.
Args: Args:
+9 -2
View File
@@ -247,7 +247,7 @@ class Calls(base.Cog):
), ),
) )
message_content = self.bot.clean_message(message, call) message_content = self.bot.clean_message(message)
if message.stickers: if message.stickers:
if participant.user.flag & ( if participant.user.flag & (
@@ -289,7 +289,7 @@ class Calls(base.Cog):
other_channel other_channel
).fetch_message(original_message_id) ).fetch_message(original_message_id)
replied_message_content = self.bot.clean_message(replied_message, call) replied_message_content = self.bot.clean_message(replied_message)
replied_participant = await call.get_participant( replied_participant = await call.get_participant(
replied_message.author.id replied_message.author.id
) )
@@ -364,6 +364,8 @@ class Calls(base.Cog):
) )
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
for _ in range(3):
try:
webhook = discord.Webhook.from_url( webhook = discord.Webhook.from_url(
await self.bot.call_handler.get_channel_webhook_url(other_channel), await self.bot.call_handler.get_channel_webhook_url(other_channel),
session=session, session=session,
@@ -385,6 +387,11 @@ class Calls(base.Cog):
message.author.id, message.author.id,
) )
break
except discord.errors.DiscordException:
await self.bot.call_handler.refresh_channel_webhook_url(other_channel)
@commands.Cog.listener() @commands.Cog.listener()
async def on_raw_message_delete( async def on_raw_message_delete(
self, payload: discord.RawMessageDeleteEvent self, payload: discord.RawMessageDeleteEvent
+23
View File
@@ -564,6 +564,29 @@ class CallHandler:
return webhook.url return webhook.url
async def refresh_channel_webhook_url(self, channel_id: int) -> str:
"""Refreshes a channel's webhook.
Args:
channel_id (int): The channel ID of the webhook to refresh.
Returns:
str: The new webhook's URL.
"""
await self.bot.redis.hdel("calls:channels:webhooks", channel_id)
channel = await self.bot.get_or_fetch_channel(channel_id)
if channel is None:
return
for webhook in await channel.webhooks():
if webhook.name == "Payphone":
await webhook.delete()
return await self.get_channel_webhook_url(channel_id)
async def get_message(self, message_id: int) -> Message | None: async def get_message(self, message_id: int) -> Message | None:
"""Gets a message sent in a call. """Gets a message sent in a call.