2023-08-17 02:50:25 -04:00
|
|
|
import discord
|
2023-08-18 14:46:24 -04:00
|
|
|
from redbot.core import Config, app_commands, commands
|
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-17 02:56:50 -04:00
|
|
|
gitea_url = None
|
2023-08-17 02:50:25 -04:00
|
|
|
)
|
|
|
|
|
2023-08-17 02:56:50 -04:00
|
|
|
@app_commands.command()
|
|
|
|
async def issuestest(self, interaction: discord.Interaction):
|
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 16:48:37 -04:00
|
|
|
channel = self.bot.get_channel(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 14:46:24 -04:00
|
|
|
await channel.send(embed=embed)
|
|
|
|
await interaction.response.send_message(content=f"Issue request sent!", embed=embed, ephemeral=True)
|
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-18 16:57:30 -04:00
|
|
|
await interaction.response.send_modal(Issues.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-18 16:57:30 -04:00
|
|
|
await interaction.response.send_modal(Issues.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="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-18 16:57:30 -04:00
|
|
|
await interaction.response.send_modal(Issues.BotBugModal(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-18 16:57:30 -04:00
|
|
|
await interaction.response.send_modal(Issues.BotBugModal(self.color, self.cog_instance, self.original_interaction))
|
2023-08-17 02:50:25 -04:00
|
|
|
|
2023-08-18 14:30:16 -04:00
|
|
|
class BotBugModal(discord.ui.Modal, title="Creating issue..."):
|
2023-08-18 16:57:30 -04:00
|
|
|
def __init__(self, color, cog_instance, original_interaction):
|
2023-08-17 02:56:50 -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:56:50 -04:00
|
|
|
|
2023-08-18 14:30:16 -04:00
|
|
|
bug_description = discord.ui.TextInput(
|
|
|
|
label="Describe the bug",
|
|
|
|
placeholder="A clear and concise description of what the bug is.",
|
|
|
|
style=discord.TextStyle.paragraph,
|
|
|
|
max_length=2048
|
|
|
|
)
|
|
|
|
reproduction_steps = discord.ui.TextInput(
|
|
|
|
label="To Reproduce",
|
|
|
|
placeholder="What caused the bug?",
|
|
|
|
style=discord.TextStyle.paragraph,
|
|
|
|
required=True,
|
|
|
|
max_length=2048
|
|
|
|
)
|
|
|
|
expected_behavior = discord.ui.TextInput(
|
|
|
|
label="Expected Behavior",
|
|
|
|
placeholder="A clear and concise description of what you expected to happen.",
|
|
|
|
style=discord.TextStyle.paragraph,
|
|
|
|
required=True,
|
|
|
|
max_length=2048
|
|
|
|
)
|
|
|
|
additional_context = discord.ui.TextInput(
|
|
|
|
label="Additional Context",
|
|
|
|
placeholder="Add any other context about the problem here.",
|
|
|
|
style=discord.TextStyle.paragraph,
|
|
|
|
required=False,
|
|
|
|
max_length=2048
|
|
|
|
)
|
2023-08-17 02:50:25 -04:00
|
|
|
|
|
|
|
async def on_submit(self, interaction: discord.Interaction):
|
2023-08-18 14:49:43 -04:00
|
|
|
embed = discord.Embed(title = "Issue Request", color = self.color)
|
2023-08-18 14:30:16 -04:00
|
|
|
fields = [self.bug_description, self.reproduction_steps, self.expected_behavior, self.additional_context]
|
|
|
|
for item in fields:
|
2023-08-18 14:17:11 -04:00
|
|
|
title = item.label
|
|
|
|
value = item.value
|
|
|
|
if value is not None:
|
2023-08-18 14:50:57 -04:00
|
|
|
embed.add_field(name=title, value=value, inline=False)
|
2023-08-18 14:46:24 -04:00
|
|
|
if interaction.user.discriminator == 0:
|
|
|
|
username = interaction.user.name
|
|
|
|
else:
|
|
|
|
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)
|
2023-08-18 16:57:30 -04:00
|
|
|
await self.cog_instance.submit_issue_request(interaction=interaction, original_interaction=self.original_interaction, embed=embed)
|