Skip to content

Commit 8fdceef

Browse files
committed
Add user selection modal for playlist sharing
Introduces a modal dialog to select a user when sharing a playlist, improving the user experience. Updates the PlaylistView to use the new BaseModal for sharing, and enhances BaseModal to support select components and store their values.
1 parent 9201ee7 commit 8fdceef

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

cogs/playlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ async def share(self, ctx: commands.Context, member: discord.Member, name: str):
473473
])
474474
@app_commands.autocomplete(name=playlist_autocomplete)
475475
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
476-
async def permission(self, ctx: commands.Context, name: str, member: discord.Member, permission: str, action: str):
476+
async def permission(self, ctx: commands.Context, member: discord.Member, name: str, permission: str, action: str):
477477
"Grant or revoke permissions for a playlist."
478478
if member.id == ctx.author.id:
479479
return await send_localized_message(ctx, 'playlist.permissions.cannotModifySelf', ephemeral=True)

voicelink/views/playlist.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from discord.ext import commands
2929
from typing import Any
3030

31-
from .utils import DynamicViewManager, Pagination
31+
from .utils import DynamicViewManager, Pagination, BaseModal
3232
from .pagination import PaginationView
3333
from ..config import Config
3434
from ..utils import format_ms, truncate_string, dispatch_message
@@ -144,7 +144,9 @@ def update_view(self, extra_states = None):
144144
async def on_error(self, interaction: discord.Interaction, error: Exception, item: discord.ui.Item) -> None:
145145
if isinstance(error, VoicelinkException):
146146
return await dispatch_message(interaction, content=getattr(error, 'original', error), ephemeral=True)
147-
147+
148+
return await super().on_error(interaction, error, item)
149+
148150
async def update_message(self, interaction: discord.Interaction) -> None:
149151
"""Update the view and edit the message with the new embed."""
150152
self.update_view()
@@ -168,7 +170,29 @@ async def play_all(self, interaction: discord.Interaction[commands.Bot], button:
168170

169171
@discord.ui.button(label="Share", custom_id="share", style=discord.ButtonStyle.gray)
170172
async def share(self, interaction: discord.Interaction[commands.Bot], button: discord.ui.Button) -> None:
171-
await interaction.response.defer()
173+
modal = BaseModal(
174+
title="Share Playlist",
175+
custom_id="share_modal",
176+
items=[
177+
discord.ui.Label(
178+
text="User to share with",
179+
description="Select a user to share with",
180+
component=discord.ui.UserSelect(
181+
custom_id="user_select",
182+
placeholder="Select a user to share with",
183+
required=True
184+
),
185+
)
186+
]
187+
)
188+
await interaction.response.send_modal(modal)
189+
await modal.wait()
190+
191+
user = modal.values.get("user_select")
192+
if not user:
193+
return
194+
195+
await interaction.client.get_command("playlist share")(self.primary_view.ctx, user[0], self.name)
172196

173197
@discord.ui.button(label="Export", custom_id="export", style=discord.ButtonStyle.gray)
174198
async def export(self, interaction: discord.Interaction[commands.Bot], button: discord.ui.Button) -> None:

voicelink/views/utils/modal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ async def on_submit(self, interaction: discord.Interaction) -> None:
4242
for item in self.walk_children():
4343
if isinstance(item, discord.ui.TextInput):
4444
self.values[item.custom_id] = item.value
45+
elif isinstance(item, (discord.ui.Select, discord.ui.UserSelect, discord.ui.RoleSelect, discord.ui.ChannelSelect, discord.ui.MentionableSelect)):
46+
self.values[item.custom_id] = item.values

0 commit comments

Comments
 (0)