This commit is contained in:
+25
-33
@@ -1,6 +1,4 @@
|
||||
"""
|
||||
Contained commands and views for record commands.
|
||||
"""
|
||||
"""Contained commands and views for record commands."""
|
||||
|
||||
import nextcord
|
||||
from discord import TextInputStyle
|
||||
@@ -11,22 +9,16 @@ from utils import record_event_points
|
||||
|
||||
|
||||
class RecordCog(commands.Cog, name="Record Commands"):
|
||||
"""
|
||||
Class holds record commands.
|
||||
"""
|
||||
"""Class holds record commands."""
|
||||
|
||||
def __init__(self, bot) -> None:
|
||||
"""
|
||||
Default constructor for RecordCog class. Does nothing.
|
||||
"""
|
||||
def __init__(self, bot: commands.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.
|
||||
"""
|
||||
async def record(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for record. Never called."""
|
||||
|
||||
@record.subcommand(description="Record an event and its participants.")
|
||||
async def event(
|
||||
@@ -37,8 +29,10 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
||||
required=False,
|
||||
description="An alternative host if you are recording event for someone else.",
|
||||
),
|
||||
):
|
||||
) -> None:
|
||||
"""
|
||||
Create and send recording event.
|
||||
|
||||
This command creates the base event recording embed and sends a message with it and the EventView
|
||||
for gathering more information on the event.
|
||||
|
||||
@@ -73,7 +67,9 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
||||
|
||||
class EventView(nextcord.ui.View):
|
||||
"""
|
||||
Class handles gathering information on an event. Has buttons to edit the information, cancel, and submit.
|
||||
Class handles gathering information on an event.
|
||||
|
||||
Has buttons to edit the information, cancel, and submit.
|
||||
Also contains a UserSelect object to pick discord members.
|
||||
"""
|
||||
|
||||
@@ -89,33 +85,31 @@ class EventView(nextcord.ui.View):
|
||||
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):
|
||||
"""
|
||||
Cancels event submission. Removes embed and view.
|
||||
"""
|
||||
async def cancel(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||
"""Cancels event submission. Removes embed and view."""
|
||||
await interaction.response.edit_message("Canceled", ephemeral=True, embed=None, view=None)
|
||||
self.stop()
|
||||
|
||||
@nextcord.ui.button(label="Edit", style=nextcord.ButtonStyle.blurple, row=1)
|
||||
async def edit(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Calls modal to update the text input information of the event.
|
||||
"""
|
||||
async def edit(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||
"""Calls modal to update the text input information of the event."""
|
||||
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):
|
||||
async def confirm(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||
"""
|
||||
Submits the event embed to the event channel. Removes view and embed from recording message.
|
||||
Submits the event embed to the event channel.
|
||||
|
||||
Removes view and embed from recording message.
|
||||
Sends point information to database.
|
||||
"""
|
||||
discord_users = self.event_participants.values.members
|
||||
discord_users = self.event_participants.values.members # noqa: PD011 not a pandas object
|
||||
if discord_users:
|
||||
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id]
|
||||
record_event_points(
|
||||
self.config,
|
||||
discord_users_list,
|
||||
True,
|
||||
True, # noqa: FBT003
|
||||
self.config.params.event_participate_points,
|
||||
)
|
||||
|
||||
@@ -175,7 +169,7 @@ class ParticipantModal(nextcord.ui.Modal):
|
||||
self.add_item(self.description)
|
||||
self.add_item(self.participants)
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
async def callback(self, interaction: nextcord.Interaction) -> None:
|
||||
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)
|
||||
@@ -184,9 +178,7 @@ class ParticipantModal(nextcord.ui.Modal):
|
||||
|
||||
|
||||
class ParticipantSelect(nextcord.ui.UserSelect):
|
||||
"""
|
||||
A selection drop down for discord members. Updates the embed with all users selected.
|
||||
"""
|
||||
"""A selection drop down for discord members. Updates the embed with all users selected."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
@@ -196,7 +188,7 @@ class ParticipantSelect(nextcord.ui.UserSelect):
|
||||
row=0,
|
||||
)
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
async def callback(self, interaction: nextcord.Interaction) -> None:
|
||||
embed: nextcord.Embed = interaction.message.embeds[0]
|
||||
participants: str = "\n".join([f"<@{participant.id}>" for participant in self.values.members])
|
||||
embed.set_field_at(0, name="Participants", value=participants)
|
||||
|
||||
Reference in New Issue
Block a user