GalaxyCogs/issues/issues.py
SeaswimmerTheFsh 5c0f74a08d
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 6s
fix(issues): testing possible fix for submit_issue_request
2023-08-18 16:39:22 -04:00

98 lines
4.7 KiB
Python

import discord
from redbot.core import Config, app_commands, commands
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)
self.config.register_global(
channel = None,
gitea_url = None
)
@app_commands.command()
async def issuestest(self, interaction: discord.Interaction):
color = await self.bot.get_embed_color(None)
await interaction.response.send_message(content="Hello world!", view=self.IssueButtons(color), ephemeral=True)
async def submit_issue_request(self, interaction: discord.Interaction, embed: discord.Embed):
channel = Issues.bot.get_channel(self.config.channel())
if channel is None:
await interaction.response.send_message(content=f"The cog is misconfigured, please report this error.", ephemeral=True)
try:
await channel.send(embed=embed)
await interaction.response.send_message(content=f"Issue request sent!", embed=embed, ephemeral=True)
except (discord.HTTPException, discord.Forbidden) as error:
await interaction.response.send_message(content=f"The cog is misconfigured, please report this error.\n```{error}```", ephemeral=True)
class IssueButtons(discord.ui.View):
def __init__(self, color):
super().__init__()
self.color = color
@discord.ui.button(label="Bot Bug", style=discord.ButtonStyle.danger, row=0)
async def issue_button_bot_bug(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(Issues.BotBugModal(self.color))
@discord.ui.button(label="Cog Bug", style=discord.ButtonStyle.danger, row=1)
async def issue_button_cog_bug(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(Issues.BotBugModal(self.color))
@discord.ui.button(label="Bot Suggestion", style=discord.ButtonStyle.blurple, row=0)
async def issue_button_bot_suggestion(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(Issues.BotBugModal(self.color))
@discord.ui.button(label="Cog Suggestion", style=discord.ButtonStyle.blurple, row=1)
async def issue_button_cog_suggestion(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(Issues.BotBugModal(self.color))
class BotBugModal(discord.ui.Modal, title="Creating issue..."):
def __init__(self, color):
super().__init__()
self.color = color
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
)
async def on_submit(self, interaction: discord.Interaction):
embed = discord.Embed(title = "Issue Request", color = self.color)
fields = [self.bug_description, self.reproduction_steps, self.expected_behavior, self.additional_context]
for item in fields:
title = item.label
value = item.value
if value is not None:
embed.add_field(name=title, value=value, inline=False)
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)
await Issues.submit_issue_request(self, interaction=interaction, embed=embed)