From f649d92808782768063204c46dcd35c412526233 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 18 Aug 2023 17:19:43 -0400 Subject: [PATCH] feat(issues): added configuration --- issues/issues.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/issues/issues.py b/issues/issues.py index fce5cae..f139c70 100644 --- a/issues/issues.py +++ b/issues/issues.py @@ -10,9 +10,18 @@ class Issues(commands.Cog): self.config = Config.get_conf(self, identifier=4285273314713, force_registration=True) self.config.register_global( request_channel = None, - gitea_url = None + gitea_repository_url = None, + gitea_token = None ) + @commands.command() + async def issuesconfig(self, ctx: commands.Context, channel: discord.TextChannel = None): + if channel: + await self.config.request_channel.set(channel) + await ctx.send(content=f"Channel set to {channel.mention}.\nRun this command again without a channel argument to configure the other settings.") + else: + await ctx.channel.send(content="Click the button below to configure the cog.", view=self.IssueConfigurationButton(self.config, ctx)) + @app_commands.command() async def issuestest(self, interaction: discord.Interaction): color = await self.bot.get_embed_color(None) @@ -102,3 +111,39 @@ class Issues(commands.Cog): username = f"{interaction.user.name}#{interaction.user.discriminator}" embed.set_footer(text=f"Submitted by {username} ({interaction.user.id})", icon_url=interaction.user.display_avatar.url) await self.cog_instance.submit_issue_request(interaction=interaction, original_interaction=self.original_interaction, embed=embed) + + class IssueConfigurationButton(discord.ui.View): + def __init__(self, config, ctx): + super().__init__() + self.config = config + self.ctx = ctx + + @discord.ui.button(label="Change Configuration", style=discord.ButtonStyle.blurple, row=0) + async def issue_configuration_button(self, interaction: discord.Interaction, button: discord.ui.Button): + await interaction.response.send_modal(Issues.IssuesConfigurationModal(self.config, self.ctx)) + + class IssuesConfigurationModal(discord.ui.Modal, title="Modifying configuration..."): + def __init__(self, config, ctx): + super().__init__() + self.config = config + self.ctx = ctx + + gitea_repository_url = discord.ui.TextInput( + label="Gitea Repository URL", + placeholder="https://try.gitea.io/owner/repository", + style=discord.TextStyle.short, + max_length=200 + ) + gitea_token = discord.ui.TextInput( + label="Gitea User Access Token", + placeholder="Generate one from your user settings page.", + style=discord.TextStyle.short, + max_length=200 + ) + + async def on_submit(self, interaction: discord.Interaction): + if self.gitea_token.value is not None: + await self.config.gitea_token.set(self.gitea_token.value) + 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!")