Add an approval process for event submissions.
build_develop / build (push) Successful in 1m25s

This commit is contained in:
2024-09-07 15:00:16 -04:00
parent d81ff295dd
commit 83d39d0002
4 changed files with 95 additions and 22 deletions
+1
View File
@@ -40,6 +40,7 @@ class EventSettings:
host_points: int host_points: int
participate_points: int participate_points: int
verify: bool
weekly_limit: int weekly_limit: int
+89 -18
View File
@@ -1,5 +1,7 @@
"""Contained commands and views for record commands.""" """Contained commands and views for record commands."""
from typing import List
import nextcord import nextcord
from discord import TextInputStyle from discord import TextInputStyle
from nextcord.ext import commands from nextcord.ext import commands
@@ -180,33 +182,74 @@ class EventView(nextcord.ui.View):
Removes view and embed from recording message. Removes view and embed from recording message.
Sends point information to database. Sends point information to database.
""" """
discord_users = self.event_participants.values.members # noqa: PD011 not a pandas object if settings.event_settings.verify:
if discord_users: verification_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.admin)
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id] verification_view = EventVerification(
record_event_points( self.event_participants.values.members, interaction.message.embeds[0].fields[1].value, self.host_id
discord_users_list,
settings.event_settings.participate_points,
is_member=True,
) )
await verification_channel.send(
non_discord_users = interaction.message.embeds[0].fields[1].value content="Event record request.", embed=interaction.message.embeds[1], view=verification_view
if non_discord_users: )
non_discord_users_list: list[str] = non_discord_users.split("\n") submission_response = "Event has been submitted to admins for approval."
record_event_points( else:
non_discord_users_list, self.process_event(
settings.event_settings.participate_points, self.event_participants.values.members,
is_member=False, interaction.message.embeds[0].fields[1].value,
self.host_id,
) )
record_event_points([self.host_id], settings.event_settings.host_points, is_member=True)
event_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.event_post) event_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.event_post)
await event_channel.send(embed=interaction.message.embeds[0]) await event_channel.send(embed=interaction.message.embeds[0])
await interaction.response.edit_message(content="Event has been submitted.", view=None, embed=None) submission_response = "Event has been submitted."
await interaction.response.edit_message(content=submission_response, view=None, embed=None)
self.stop() self.stop()
class EventVerification(nextcord.ui.View):
"""Class contains code to approve/deny event submissions."""
def __init__(
self,
discord_users: list[nextcord.Member],
non_discord_users: str,
host_id: int,
):
super().__init__(timeout=None, auto_defer=True)
self.discord_users: list[nextcord.Member] = discord_users
self.non_discord_users: str = non_discord_users
self.host_id: int = host_id
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green)
async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Approve button for an event submission.
Calls the process event function. Records who approved the event.
Removes the view from the interaction message.
Args:
button (nextcord.ui.Button): Unused.
interaction (nextcord.Interaction): The interaction of the user clicking the button.
"""
process_event(self.discord_users, self.non_discord_users, self.host_id)
content = f"\nApproved by <@{interaction.user.id}>."
await interaction.response.edit_message(content=content, view=None)
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red)
async def deny(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Deny button for an event submission. Just removes the view and logs who denied the request.
Args:
button (nextcord.ui.Button): Unused.
interaction (nextcord.Interaction): The interaction of the user clicking the button.
"""
content = f"\nDenied by <@{interaction.user.id}>."
await interaction.response.edit_message(content=content, view=None)
class ParticipantModal(nextcord.ui.Modal): class ParticipantModal(nextcord.ui.Modal):
""" """
This modal contains all the text edits for an event. This modal contains all the text edits for an event.
@@ -281,3 +324,31 @@ class ParticipantSelect(nextcord.ui.UserSelect):
participants: str = "\n".join([f"<@{participant.id}>" for participant in self.values.members]) participants: str = "\n".join([f"<@{participant.id}>" for participant in self.values.members])
embed.set_field_at(0, name="Participants", value=participants) embed.set_field_at(0, name="Participants", value=participants)
await interaction.response.edit_message(embed=embed) await interaction.response.edit_message(embed=embed)
def process_event(discord_users: list[nextcord.Member], non_discord_users: str, host_id: int) -> None:
"""
Processes all points to give to participants and host for an event.
Args:
discord_users (list[nextcord.Member]): List of discord members that participated in event.
non_discord_users (str): Newline separated list of non discord members that participated in event.
host_id (int): Discord ID of host.
"""
if discord_users:
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not host_id]
record_event_points(
discord_users_list,
settings.event_settings.participate_points,
is_member=True,
)
if non_discord_users:
non_discord_users_list: list[str] = non_discord_users.split("\n")
record_event_points(
non_discord_users_list,
settings.event_settings.participate_points,
is_member=False,
)
record_event_points([host_id], settings.event_settings.host_points, is_member=True)
+1 -1
View File
@@ -109,7 +109,7 @@ class UsernameRequest(nextcord.ui.View):
await interaction.followup.edit_message(interaction.message.id, content=content, view=None) await interaction.followup.edit_message(interaction.message.id, content=content, view=None)
else: else:
await interaction.response.edit_message( await interaction.response.edit_message(
content="An error occured while changing the user's nickname.", content="An error occurred while changing the user's nickname.",
view=None, view=None,
) )
+1
View File
@@ -85,6 +85,7 @@ ignore = [
"E117", "E117",
"ISC001", "ISC001",
"ISC002", "ISC002",
"PD011", # doesn't like me using '.values' on embeds....
"Q000", "Q000",
"Q001", "Q001",
"Q002", "Q002",