Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

private gpu view #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/discord-cluster-manager/cogs/leaderboard_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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()

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading