2023-08-17 02:50:25 -04:00
|
|
|
import discord
|
2023-08-19 16:54:55 -04:00
|
|
|
from redbot.core import Config, app_commands, commands, checks
|
2023-08-20 15:52:35 -04:00
|
|
|
from . import modals
|
2023-08-17 02:50:25 -04:00
|
|
|
|
|
|
|
class Issues(commands.Cog):
|
|
|
|
"""This cog allows you to create Gitea issues through a Discord modal.
|
|
|
|
Developed by SeaswimmerTheFsh."""
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
self.config = Config.get_conf(self, identifier=4285273314713, force_registration=True)
|
2023-08-17 02:56:50 -04:00
|
|
|
self.config.register_global(
|
2023-08-18 16:48:37 -04:00
|
|
|
request_channel = None,
|
2023-08-19 17:42:10 -04:00
|
|
|
gitea_root_url = None,
|
|
|
|
gitea_repository_owner = None,
|
|
|
|
gitea_repository = None,
|
2023-08-18 17:19:43 -04:00
|
|
|
gitea_token = None
|
2023-08-17 02:50:25 -04:00
|
|
|
)
|
|
|
|
|
2023-08-18 17:19:43 -04:00
|
|
|
@commands.command()
|
2023-08-19 16:54:55 -04:00
|
|
|
@checks.is_owner()
|
2023-08-18 17:19:43 -04:00
|
|
|
async def issuesconfig(self, ctx: commands.Context, channel: discord.TextChannel = None):
|
|
|
|
if channel:
|
2023-08-18 17:21:12 -04:00
|
|
|
await self.config.request_channel.set(channel.id)
|
2023-08-18 17:19:43 -04:00
|
|
|
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))
|
|
|
|
|
2023-08-17 02:56:50 -04:00
|
|
|
@app_commands.command()
|
2023-08-20 15:48:26 -04:00
|
|
|
async def issues(self, interaction: discord.Interaction):
|
|
|
|
"""Found a bug or have a suggestion for the Galaxy bot? Use this command."""
|
2023-08-18 14:49:43 -04:00
|
|
|
color = await self.bot.get_embed_color(None)
|
2023-08-18 16:57:30 -04:00
|
|
|
await interaction.response.send_message(content="Hello world!", view=self.IssueButtons(color, self, interaction), ephemeral=True)
|
2023-08-17 02:50:25 -04:00
|
|
|
|
2023-08-18 16:57:30 -04:00
|
|
|
async def submit_issue_request(self, interaction: discord.Interaction, original_interaction: discord.Interaction, embed: discord.Embed):
|
2023-08-18 17:24:15 -04:00
|
|
|
channel = self.bot.get_channel(await self.config.request_channel())
|
2023-08-18 14:46:24 -04:00
|
|
|
if channel is None:
|
2023-08-18 16:57:30 -04:00
|
|
|
await original_interaction.edit_original_response(content="Command cancelled.", view=None)
|
2023-08-18 14:46:24 -04:00
|
|
|
await interaction.response.send_message(content=f"The cog is misconfigured, please report this error.", ephemeral=True)
|
2023-08-17 02:50:25 -04:00
|
|
|
try:
|
2023-08-18 17:55:47 -04:00
|
|
|
message = await channel.send(content=".")
|
|
|
|
await message.edit(content="", embed=embed, view=self.IssueResponseButtons(channel, message.id, interaction.user))
|
2023-08-18 17:32:22 -04:00
|
|
|
await original_interaction.edit_original_response(content=f"Issue request sent!", embed=embed, view=None)
|
2023-08-18 18:03:57 -04:00
|
|
|
await interaction.response.defer()
|
2023-08-17 02:50:25 -04:00
|
|
|
except (discord.HTTPException, discord.Forbidden) as error:
|
2023-08-18 16:57:30 -04:00
|
|
|
await original_interaction.edit_original_response(content="Command cancelled.", view=None)
|
2023-08-18 14:46:24 -04:00
|
|
|
await interaction.response.send_message(content=f"The cog is misconfigured, please report this error.\n```{error}```", ephemeral=True)
|
2023-08-17 02:50:25 -04:00
|
|
|
|
|
|
|
class IssueButtons(discord.ui.View):
|
2023-08-18 16:57:30 -04:00
|
|
|
def __init__(self, color, cog_instance, original_interaction):
|
2023-08-17 02:50:25 -04:00
|
|
|
super().__init__()
|
2023-08-18 14:49:43 -04:00
|
|
|
self.color = color
|
2023-08-18 16:45:02 -04:00
|
|
|
self.cog_instance = cog_instance
|
2023-08-18 16:57:30 -04:00
|
|
|
self.original_interaction = original_interaction
|
2023-08-17 02:50:25 -04:00
|
|
|
|
2023-08-18 13:18:52 -04:00
|
|
|
@discord.ui.button(label="Bot Bug", style=discord.ButtonStyle.danger, row=0)
|
2023-08-18 13:34:22 -04:00
|
|
|
async def issue_button_bot_bug(self, interaction: discord.Interaction, button: discord.ui.Button):
|
2023-08-20 15:48:26 -04:00
|
|
|
await interaction.response.send_modal(modals.BotBugModal(self.color, self.cog_instance, self.original_interaction))
|
2023-08-18 13:18:52 -04:00
|
|
|
|
2023-08-18 13:21:19 -04:00
|
|
|
@discord.ui.button(label="Cog Bug", style=discord.ButtonStyle.danger, row=1)
|
2023-08-18 13:34:22 -04:00
|
|
|
async def issue_button_cog_bug(self, interaction: discord.Interaction, button: discord.ui.Button):
|
2023-08-20 15:48:26 -04:00
|
|
|
await interaction.response.send_modal(modals.CogBugModal(self.color, self.cog_instance, self.original_interaction))
|
2023-08-18 13:18:52 -04:00
|
|
|
|
2023-08-18 13:21:19 -04:00
|
|
|
@discord.ui.button(label="Bot Suggestion", style=discord.ButtonStyle.blurple, row=0)
|
2023-08-18 13:34:22 -04:00
|
|
|
async def issue_button_bot_suggestion(self, interaction: discord.Interaction, button: discord.ui.Button):
|
2023-08-20 15:48:26 -04:00
|
|
|
await interaction.response.send_modal(modals.BotSuggestionModal(self.color, self.cog_instance, self.original_interaction))
|
2023-08-18 13:18:52 -04:00
|
|
|
|
|
|
|
@discord.ui.button(label="Cog Suggestion", style=discord.ButtonStyle.blurple, row=1)
|
2023-08-18 13:34:22 -04:00
|
|
|
async def issue_button_cog_suggestion(self, interaction: discord.Interaction, button: discord.ui.Button):
|
2023-08-20 15:48:26 -04:00
|
|
|
await interaction.response.send_modal(modals.CogSuggestionModal(self.color, self.cog_instance, self.original_interaction))
|
2023-08-18 17:19:43 -04:00
|
|
|
|
|
|
|
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):
|
2023-08-20 15:48:26 -04:00
|
|
|
await interaction.response.send_modal(modals.IssuesConfigurationModal(self.config, self.ctx))
|
2023-08-18 17:55:47 -04:00
|
|
|
|
|
|
|
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):
|
2023-08-20 15:48:26 -04:00
|
|
|
await interaction.response.send_modal(modals.IssueResponseModal(self.channel, self.message_id, self.user, True))
|
2023-08-18 17:55:47 -04:00
|
|
|
|
2023-08-18 17:57:25 -04:00
|
|
|
@discord.ui.button(label="Deny", style=discord.ButtonStyle.danger)
|
2023-08-18 17:55:47 -04:00
|
|
|
async def issue_response_button_deny(self, interaction: discord.Interaction, button: discord.ui.Button):
|
2023-08-20 15:48:26 -04:00
|
|
|
await interaction.response.send_modal(modals.IssueResponseModal(self.channel, self.message_id, self.user, False))
|