Enhance error handling and improve message ID storage in ControlPanel and WaitingRoom
Some checks failed
Run pre-commit / Run pre-commit (push) Has been cancelled

This update refines the error handling in the ControlPanel and WaitingRoom classes, ensuring that exceptions are logged and handled gracefully. Additionally, it improves the storage of message IDs for both control panel and waiting room messages, enhancing the overall reliability and functionality of the AutoRoom feature.
This commit is contained in:
Valerie 2025-06-13 20:02:18 -04:00
parent 628f2dae90
commit 60a2cb1f4f
3 changed files with 99 additions and 60 deletions

View file

@ -68,8 +68,9 @@ class AutoRoom(
"owner": None,
"associated_text_channel": None,
"denied": [],
"message_id": None,
"waiting_room_message_id": None,
"message_id": None, # For control panel message ID
"control_panel_message_id": None, # Alternative name for control panel message ID
"waiting_room_message_id": None, # For waiting room message ID
}
extra_channel_name_change_delay = 4

View file

@ -197,6 +197,7 @@ class ControlPanel:
async def create_control_panel(self, autoroom: discord.VoiceChannel) -> None:
"""Create the control panel embed in the voice channel's text chat."""
try:
autoroom_info = await self.cog.get_autoroom_info(autoroom)
if not autoroom_info:
return
@ -213,6 +214,13 @@ class ControlPanel:
break
if not text_channel:
# If no matching text channel found, try to get the default text channel
text_channel = autoroom.guild.system_channel
if not text_channel:
return
# Check if we have permission to send messages
if not text_channel.permissions_for(autoroom.guild.me).send_messages:
return
# Create the embed
@ -234,5 +242,17 @@ class ControlPanel:
# Send the embed to the text channel
message = await text_channel.send(embed=embed, view=view)
# Store the message ID for reference
# Store the message ID for reference (using both field names for compatibility)
await self.config.channel(autoroom).message_id.set(message.id)
await self.config.channel(autoroom).control_panel_message_id.set(message.id)
except discord.NotFound:
# Channel was deleted or we lost access
return
except discord.Forbidden:
# We don't have permission to send messages
return
except Exception as e:
# Log any other errors
print(f"Error creating control panel: {e}")
return

View file

@ -137,6 +137,7 @@ class WaitingRoom:
async def handle_waiting_user(self, member: discord.Member, autoroom: discord.VoiceChannel) -> None:
"""Handle a user joining the waiting room."""
try:
autoroom_info = await self.cog.get_autoroom_info(autoroom)
if not autoroom_info:
return
@ -149,6 +150,13 @@ class WaitingRoom:
break
if not text_channel:
# If no matching text channel found, try to get the default text channel
text_channel = autoroom.guild.system_channel
if not text_channel:
return
# Check if we have permission to send messages
if not text_channel.permissions_for(autoroom.guild.me).send_messages:
return
# Create waiting message with buttons
@ -160,6 +168,16 @@ class WaitingRoom:
# Save message ID
await self.config.channel(autoroom).waiting_room_message_id.set(message.id)
except discord.NotFound:
# Channel was deleted or we lost access
return
except discord.Forbidden:
# We don't have permission to send messages
return
except Exception as e:
# Log any other errors
print(f"Error handling waiting user: {e}")
return
async def cleanup_waiting_room(self, autoroom_source: discord.VoiceChannel) -> None:
"""Clean up the waiting room when disabling it."""