Refactor ControlPanelView to utilize voice channel references
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This update modifies the ControlPanelView class to retrieve voice channel information from interaction messages, ensuring accurate AutoRoom management. It also updates the context handling for allow/deny actions, improving the overall functionality and user experience of the AutoRoom feature.
This commit is contained in:
Valerie 2025-06-13 19:35:00 -04:00
parent f986a23d2b
commit 84410f9b20

View file

@ -20,8 +20,14 @@ class ControlPanelView(ui.View):
if not interaction.message:
return
# Get the voice channel from the message
voice_channel = interaction.guild.get_channel(interaction.message.reference.channel_id)
if not isinstance(voice_channel, discord.VoiceChannel):
await interaction.response.send_message("Could not find the voice channel.", ephemeral=True)
return
# Get the AutoRoom info
autoroom_info = await self.cog.get_autoroom_info(interaction.channel)
autoroom_info = await self.cog.get_autoroom_info(voice_channel)
if not autoroom_info:
await interaction.response.send_message("This is not an AutoRoom.", ephemeral=True)
return
@ -32,7 +38,9 @@ class ControlPanelView(ui.View):
return
# Make the AutoRoom public
await self.cog._process_allow_deny(interaction, "allow")
ctx = await self.cog.bot.get_context(interaction.message)
ctx.author = interaction.user
await self.cog._process_allow_deny(ctx, "allow")
await interaction.response.send_message("AutoRoom is now public.", ephemeral=True)
@discord.ui.button(label="🔒 Locked", style=discord.ButtonStyle.grey, custom_id="autoroom_locked")
@ -41,8 +49,14 @@ class ControlPanelView(ui.View):
if not interaction.message:
return
# Get the voice channel from the message
voice_channel = interaction.guild.get_channel(interaction.message.reference.channel_id)
if not isinstance(voice_channel, discord.VoiceChannel):
await interaction.response.send_message("Could not find the voice channel.", ephemeral=True)
return
# Get the AutoRoom info
autoroom_info = await self.cog.get_autoroom_info(interaction.channel)
autoroom_info = await self.cog.get_autoroom_info(voice_channel)
if not autoroom_info:
await interaction.response.send_message("This is not an AutoRoom.", ephemeral=True)
return
@ -53,7 +67,9 @@ class ControlPanelView(ui.View):
return
# Make the AutoRoom locked
await self.cog._process_allow_deny(interaction, "lock")
ctx = await self.cog.bot.get_context(interaction.message)
ctx.author = interaction.user
await self.cog._process_allow_deny(ctx, "lock")
await interaction.response.send_message("AutoRoom is now locked.", ephemeral=True)
@discord.ui.button(label="🔐 Private", style=discord.ButtonStyle.red, custom_id="autoroom_private")
@ -62,8 +78,14 @@ class ControlPanelView(ui.View):
if not interaction.message:
return
# Get the voice channel from the message
voice_channel = interaction.guild.get_channel(interaction.message.reference.channel_id)
if not isinstance(voice_channel, discord.VoiceChannel):
await interaction.response.send_message("Could not find the voice channel.", ephemeral=True)
return
# Get the AutoRoom info
autoroom_info = await self.cog.get_autoroom_info(interaction.channel)
autoroom_info = await self.cog.get_autoroom_info(voice_channel)
if not autoroom_info:
await interaction.response.send_message("This is not an AutoRoom.", ephemeral=True)
return
@ -74,7 +96,9 @@ class ControlPanelView(ui.View):
return
# Make the AutoRoom private
await self.cog._process_allow_deny(interaction, "deny")
ctx = await self.cog.bot.get_context(interaction.message)
ctx.author = interaction.user
await self.cog._process_allow_deny(ctx, "deny")
await interaction.response.send_message("AutoRoom is now private.", ephemeral=True)
@discord.ui.button(label="👥 Add User", style=discord.ButtonStyle.blurple, custom_id="autoroom_add_user")
@ -83,8 +107,14 @@ class ControlPanelView(ui.View):
if not interaction.message:
return
# Get the voice channel from the message
voice_channel = interaction.guild.get_channel(interaction.message.reference.channel_id)
if not isinstance(voice_channel, discord.VoiceChannel):
await interaction.response.send_message("Could not find the voice channel.", ephemeral=True)
return
# Get the AutoRoom info
autoroom_info = await self.cog.get_autoroom_info(interaction.channel)
autoroom_info = await self.cog.get_autoroom_info(voice_channel)
if not autoroom_info:
await interaction.response.send_message("This is not an AutoRoom.", ephemeral=True)
return
@ -104,8 +134,14 @@ class ControlPanelView(ui.View):
if not interaction.message:
return
# Get the voice channel from the message
voice_channel = interaction.guild.get_channel(interaction.message.reference.channel_id)
if not isinstance(voice_channel, discord.VoiceChannel):
await interaction.response.send_message("Could not find the voice channel.", ephemeral=True)
return
# Get the AutoRoom info
autoroom_info = await self.cog.get_autoroom_info(interaction.channel)
autoroom_info = await self.cog.get_autoroom_info(voice_channel)
if not autoroom_info:
await interaction.response.send_message("This is not an AutoRoom.", ephemeral=True)
return
@ -152,8 +188,16 @@ class UserSelectModal(ui.Modal, title="Select User"):
await interaction.response.send_message("User not found in this server.", ephemeral=True)
return
# Get the voice channel from the message
voice_channel = interaction.guild.get_channel(interaction.message.reference.channel_id)
if not isinstance(voice_channel, discord.VoiceChannel):
await interaction.response.send_message("Could not find the voice channel.", ephemeral=True)
return
# Process the allow/deny action
await self.cog._process_allow_deny(interaction, self.action, member_or_role=user)
ctx = await self.cog.bot.get_context(interaction.message)
ctx.author = interaction.user
await self.cog._process_allow_deny(ctx, self.action, member_or_role=user)
await interaction.response.send_message(f"User {user.mention} has been {'allowed' if self.action == 'allow' else 'denied'} access.", ephemeral=True)
class ControlPanel:
@ -174,11 +218,7 @@ class ControlPanel:
if not owner:
return
# Get the voice channel's text chat
text_channel = autoroom.guild.get_channel(autoroom.id)
if not text_channel:
return
# Create the embed
embed = discord.Embed(
title="AutoRoom Control Panel",
description=f"Control panel for {autoroom.mention}\nOwner: {owner.mention}",
@ -196,4 +236,6 @@ class ControlPanel:
view = ControlPanelView(self.cog)
# Send the embed
await text_channel.send(embed=embed, view=view)
message = await autoroom.send(embed=embed, view=view)
# Store the message ID for reference
await self.config.channel(autoroom).control_panel_message_id.set(message.id)