From 3d53d4f259d50935b833bc81b3a128cc523a521d Mon Sep 17 00:00:00 2001 From: Andre Date: Fri, 27 Dec 2024 19:52:48 -0700 Subject: [PATCH] private gpu view --- .../cogs/leaderboard_cog.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/discord-cluster-manager/cogs/leaderboard_cog.py b/src/discord-cluster-manager/cogs/leaderboard_cog.py index 71b00a3..65b38d7 100644 --- a/src/discord-cluster-manager/cogs/leaderboard_cog.py +++ b/src/discord-cluster-manager/cogs/leaderboard_cog.py @@ -205,7 +205,7 @@ async def submit_github( await send_discord_message(interaction, "❌ Required cogs not found!") return - view = GPUSelectionView(gpus) + view = GPUSelectionView(gpus, interaction.user) await send_discord_message( interaction, @@ -243,8 +243,10 @@ async def submit_github( class GPUSelectionView(ui.View): - def __init__(self, available_gpus: list[str]): + def __init__(self, available_gpus: list[str], original_user: discord.User): super().__init__() + self.original_user = original_user + self.selected_gpus = None # Add the Select Menu with the list of GPU options select = ui.Select( @@ -256,14 +258,20 @@ def __init__(self, available_gpus: list[str]): select.callback = self.select_callback self.add_item(select) + async def interaction_check(self, interaction: discord.Interaction) -> bool: + if interaction.user != self.original_user: + await interaction.response.send_message( + f"This selection menu is only for {self.original_user.name}!", ephemeral=True + ) + return False + return True + async def select_callback(self, interaction: Interaction): # Retrieve the selected options select = interaction.data["values"] self.selected_gpus = select await send_discord_message( - interaction, - f"Selected GPUs: {', '.join(self.selected_gpus)}", - ephemeral=True, + interaction, f"Selected GPUs: {', '.join(self.selected_gpus)}", ephemeral=True ) self.stop() @@ -391,7 +399,7 @@ async def leaderboard_create( return # Ask the user to select GPUs - view = GPUSelectionView([gpu.name for gpu in GitHubGPU]) + view = GPUSelectionView([gpu.name for gpu in GitHubGPU], interaction.user) await send_discord_message( interaction, @@ -477,7 +485,7 @@ async def get_leaderboard_submissions( if not interaction.response.is_done(): await interaction.response.defer() - view = GPUSelectionView(gpus) + view = GPUSelectionView(gpus, interaction.user) await send_discord_message( interaction,