""" Contained commands and views for record commands. """ import nextcord from nextcord.ext import commands from config import DakinyConfig class RecordCog(commands.Cog, name="Record Commands"): """ Class holds record commands. """ def __init__(self, bot) -> None: """ Default constructor for RecordCog class. Does nothing. """ super().__init__() self.bot: commands.Bot = bot @nextcord.slash_command() async def record(self, interaction: nextcord.Interaction): """ Parent slash command for record. Never called. """ @record.subcommand(description="Record an event and its participants.") async def event( self, interaction: nextcord.Interaction, name: str = nextcord.SlashOption( required=True, description="Name of the event that was hosted." ), host: nextcord.Member = nextcord.SlashOption( required=False, description="An alternative host if you are recording event for someone else.", ), ): # check role if ( interaction.guild.get_role(self.bot.config.params.event_host_role_id) not in interaction.user.roles ): await interaction.response.send_message( f"You must have the <@&{self.bot.config.params.event_host_role_id}> role to record an event.", ephemeral=True, ) return if host is None: host = interaction.user await interaction.response.send_message( "Select all members who participated!", view=EventView(host, name, self.bot.config), ephemeral=True, ) # add points to table class EventView(nextcord.ui.View): def __init__(self, host: nextcord.Member, name: str, config: DakinyConfig): super().__init__() self.host: nextcord.Member = host self.name: str = name self.config: DakinyConfig = config self.event_participants = nextcord.ui.UserSelect( min_values=1, max_values=25, placeholder="Select all participants", row=0, ) self.add_item(self.event_participants) @nextcord.ui.button(label="Cancel", style=nextcord.ButtonStyle.red, row=1) async def cancel( self, button: nextcord.ui.Button, interaction: nextcord.Interaction ): await interaction.response.send_message("Cancelling", ephemeral=True) self.stop() @nextcord.ui.button(label="Confirm", style=nextcord.ButtonStyle.green, row=1) async def confirm( self, button: nextcord.ui.Button, interaction: nextcord.Interaction ): msg = f"Event: {self.name}\n" msg += f"Hosted by: <@{self.host.id}>\n\n" msg += "Participants:\n" for participant in self.event_participants.values.members: msg += f"<@{participant.id}>\n" event_channel: nextcord.TextChannel = interaction.guild.get_channel( self.config.params.event_post_channel_id ) await event_channel.send(msg) self.stop()