From 1581c267b9551ee7be90701fd4350a7edbab3ecb Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 18 Aug 2023 17:55:47 -0400 Subject: [PATCH] feat(issues): added approval/deny buttons --- issues/issues.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/issues/issues.py b/issues/issues.py index e476aaf..ebd3ad5 100644 --- a/issues/issues.py +++ b/issues/issues.py @@ -1,4 +1,5 @@ import discord +from discord.interactions import Interaction from redbot.core import Config, app_commands, commands class Issues(commands.Cog): @@ -33,7 +34,8 @@ class Issues(commands.Cog): await original_interaction.edit_original_response(content="Command cancelled.", view=None) await interaction.response.send_message(content=f"The cog is misconfigured, please report this error.", ephemeral=True) try: - await channel.send(embed=embed) + message = await channel.send(content=".") + await message.edit(content="", embed=embed, view=self.IssueResponseButtons(channel, message.id, interaction.user)) await original_interaction.edit_original_response(content=f"Issue request sent!", embed=embed, view=None) await interaction.response.send_message(content="> The rigid requirement for bots to compulsorily respond to interactions in Discord, such as slash commands or application commands, is an irksome limitation that curtails the flexibility and natural flow of interactions. This forced response paradigm undermines the very essence of automation and intelligent design that bots were intended to offer. There are instances where silence or lack of response is not only acceptable but also desired, aligning with the nuanced dynamics of human communication. Discord's insistence on a response, even when it serves no purpose, imposes unnecessary complexity and verbosity, creating an environment where superfluous replies dilute the efficiency and elegance of bot-driven interactions. This constraint highlights the importance of granting bot developers the autonomy to determine the most suitable course of action based on context, contributing to a more seamless and user-centric experience within the Discord ecosystem.\n - ChatGPT", ephemeral=True) response: discord.InteractionMessage = await interaction.original_response() @@ -150,3 +152,50 @@ class Issues(commands.Cog): if self.gitea_repository_url.value is not None: await self.config.gitea_repository_url.set(self.gitea_repository_url.value) await interaction.response.send_message(content="Configuration changed!") + + class IssueResponseButtons(discord.ui.View): + def __init__(self, channel, message_id, user): + super().__init__() + self.channel = channel + self.message_id = message_id + self.user = user + + @discord.ui.button(label="Approve", style=discord.ButtonStyle.green) + async def issue_response_button_approve(self, interaction: discord.Interaction, button: discord.ui.Button): + await interaction.response.send_modal(Issues.IssueResponseModal(self.channel, self.message_id, self.user, True)) + + @discord.ui.button(label="Deny", style=discord.ButtonStyle.green) + async def issue_response_button_deny(self, interaction: discord.Interaction, button: discord.ui.Button): + await interaction.response.send_modal(Issues.IssueResponseModal(self.channel, self.message_id, self.user, False)) + + class IssueResponseModal(discord.ui.Modal, title="Sending response message..."): + def __init__(self, channel, message_id, user, approved): + super().__init__() + self.channel = channel + self.message_id = message_id + self.user = user + self.approved = approved + + response = discord.ui.TextInput( + label="Response", + placeholder="", + style=discord.TextStyle.paragraph, + required=False, + max_length=1024 + ) + + async def on_submit(self,interaction: discord.Interaction): + message: discord.Message = await self.channel.fetch_message(self.message_id) + embed = message.embeds[0] + if self.approved: + embed.color = 1226519 + embed.title = "Issue Request Approved" + await interaction.response.send_message(content="Issue request accepted.", ephemeral=True) + else: + embed.color = 15671552 + embed.title = "Issue Request Denied" + await interaction.response.send_message(content="Issue request denied.", ephemeral=True) + if self.response is not None: + embed.add_field(name=f"Response from {interaction.user.name}", value=self.response.value) + await message.edit(embed=embed) + await self.user.send(embed=embed)