From bd3debf0259cb6197b204d2eae8041f444d978e0 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Thu, 9 May 2024 16:26:20 -0400 Subject: [PATCH] Change up recording process. use a modal to edit text values. --- cogs/commands/record.py | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/cogs/commands/record.py b/cogs/commands/record.py index e378863..42ca1dc 100644 --- a/cogs/commands/record.py +++ b/cogs/commands/record.py @@ -3,6 +3,7 @@ Contained commands and views for record commands. """ import nextcord +from discord import TextInputStyle from nextcord.ext import commands from config import DakinyConfig @@ -52,10 +53,15 @@ class RecordCog(commands.Cog, name="Record Commands"): if host is None: host = interaction.user + embed: nextcord.Embed = nextcord.Embed(title=name, description="") + embed.add_field(name="Participants", value="") + embed.add_field(name="Non-Discord Participants", value="") + await interaction.response.send_message( "Select all members who participated!", view=EventView(host, name, self.bot.config), ephemeral=True, + embed=embed, ) # add points to table @@ -85,6 +91,12 @@ class EventView(nextcord.ui.View): await interaction.response.send_message("Cancelling", ephemeral=True) self.stop() + @nextcord.ui.button(label="Edit", style=nextcord.ButtonStyle.blurple, row=1) + async def edit(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + await interaction.response.send_modal( + ParticipantModal(interaction.message.embeds[0]) + ) + @nextcord.ui.button(label="Confirm", style=nextcord.ButtonStyle.green, row=1) async def confirm( self, button: nextcord.ui.Button, interaction: nextcord.Interaction @@ -100,3 +112,44 @@ class EventView(nextcord.ui.View): ) await event_channel.send(msg) self.stop() + + +class ParticipantModal(nextcord.ui.Modal): + def __init__(self, embed): + super().__init__( + "Add non-discord members as participats!", + timeout=5 * 60, + ) + self.embed: nextcord.Embed = embed + self.name: nextcord.ui.TextInput = nextcord.ui.TextInput( + required=True, + label="Event Name", + default_value=self.embed.title, + ) + self.description: nextcord.ui.TextInput = nextcord.ui.TextInput( + required=False, + label="Event Description", + default_value=self.embed.description, + style=TextInputStyle.paragraph, + placeholder="Add a description if desired.", + max_length=1000, + ) + self.participants: nextcord.ui.TextInput = nextcord.ui.TextInput( + required=False, + label="Usernames", + style=TextInputStyle.paragraph, + placeholder="Please separate usernames with a new line.", + default_value=self.embed.fields[1].value, + ) + self.add_item(self.name) + self.add_item(self.description) + self.add_item(self.participants) + + async def callback(self, interaction: nextcord.Interaction): + self.embed.title = self.name.value + self.embed.description = self.description.value + self.embed.set_field_at( + index=1, name="Non-Discord Participants", value=self.participants.value + ) + + await interaction.response.edit_message(embed=self.embed)