Compare commits
2 commits
88ce09cb2d
...
246242ad71
Author | SHA1 | Date | |
---|---|---|---|
246242ad71 | |||
83b7c3f17e |
1 changed files with 49 additions and 86 deletions
|
@ -1,6 +1,5 @@
|
||||||
from typing import Union
|
|
||||||
from redbot.core import commands, Config, app_commands
|
|
||||||
import discord
|
import discord
|
||||||
|
from redbot.core import Config, app_commands, commands
|
||||||
|
|
||||||
class Issues(commands.Cog):
|
class Issues(commands.Cog):
|
||||||
"""This cog allows you to create Gitea issues through a Discord modal.
|
"""This cog allows you to create Gitea issues through a Discord modal.
|
||||||
|
@ -19,23 +18,15 @@ class Issues(commands.Cog):
|
||||||
passed_info = interaction
|
passed_info = interaction
|
||||||
await interaction.response.send_message(content="Hello world!", view=self.IssueButtons(passed_info), ephemeral=True)
|
await interaction.response.send_message(content="Hello world!", view=self.IssueButtons(passed_info), ephemeral=True)
|
||||||
|
|
||||||
async def send_to_target(self, target: Union[discord.Member, discord.TextChannel], interaction: discord.Interaction, message: str, secondary_message: str = None):
|
async def submit_issue_request(self, interaction: discord.Interaction, embed: discord.Embed):
|
||||||
if isinstance(target, discord.Member):
|
channel = self.bot.get_channel(self.config.channel())
|
||||||
target_type = "member"
|
if channel is None:
|
||||||
elif isinstance(target, discord.TextChannel):
|
await interaction.response.send_message(content=f"The cog is misconfigured, please report this error.", ephemeral=True)
|
||||||
target_type = "textchannel"
|
|
||||||
try:
|
try:
|
||||||
await target.send(message)
|
await channel.send(embed=embed)
|
||||||
if secondary_message is not None:
|
await interaction.response.send_message(content=f"Issue request sent!", embed=embed, ephemeral=True)
|
||||||
await target.send(secondary_message)
|
|
||||||
await interaction.response.send_message(content=f"Message sent to {target.mention}!\nMessage contents:\n```{message}```\n```{secondary_message}```", ephemeral=True)
|
|
||||||
else:
|
|
||||||
await interaction.response.send_message(content=f"Message sent to {target.mention}!\nMessage contents:\n```{message}```", ephemeral=True)
|
|
||||||
except (discord.HTTPException, discord.Forbidden) as error:
|
except (discord.HTTPException, discord.Forbidden) as error:
|
||||||
if target_type == "member":
|
await interaction.response.send_message(content=f"The cog is misconfigured, please report this error.\n```{error}```", ephemeral=True)
|
||||||
await interaction.response.send_message(content="That user has their direct messages closed!", ephemeral=True)
|
|
||||||
elif target_type == "textchannel":
|
|
||||||
await interaction.response.send_message(content="I cannot access that channel!", ephemeral=True)
|
|
||||||
|
|
||||||
class IssueButtons(discord.ui.View):
|
class IssueButtons(discord.ui.View):
|
||||||
def __init__(self, passed_info):
|
def __init__(self, passed_info):
|
||||||
|
@ -44,91 +35,63 @@ class Issues(commands.Cog):
|
||||||
|
|
||||||
@discord.ui.button(label="Bot Bug", style=discord.ButtonStyle.danger, row=0)
|
@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):
|
async def issue_button_bot_bug(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
await interaction.response.send_modal(Issues.IssuesModal(button_id="bot_bug"))
|
await interaction.response.send_modal(Issues.BotBugModal())
|
||||||
|
|
||||||
@discord.ui.button(label="Cog Bug", style=discord.ButtonStyle.danger, row=1)
|
@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):
|
async def issue_button_cog_bug(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
await interaction.response.send_modal(Issues.IssuesModal(button_id="cog_bug"))
|
await interaction.response.send_modal(Issues.BotBugModal())
|
||||||
|
|
||||||
@discord.ui.button(label="Bot Suggestion", style=discord.ButtonStyle.blurple, row=0)
|
@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):
|
async def issue_button_bot_suggestion(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
await interaction.response.send_modal(Issues.IssuesModal(button_id="bot_suggestion"))
|
await interaction.response.send_modal(Issues.BotBugModal())
|
||||||
|
|
||||||
@discord.ui.button(label="Cog Suggestion", style=discord.ButtonStyle.blurple, row=1)
|
@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):
|
async def issue_button_cog_suggestion(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
await interaction.response.send_modal(Issues.IssuesModal(button_id="cog_suggestion"))
|
await interaction.response.send_modal(Issues.BotBugModal())
|
||||||
|
|
||||||
class IssuesModal(discord.ui.Modal, title="Creating issue..."):
|
class BotBugModal(discord.ui.Modal, title="Creating issue..."):
|
||||||
def __init__(self, button_id):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.button_id = button_id
|
|
||||||
self.input_list = []
|
|
||||||
|
|
||||||
if self.button_id == "cog_suggestion" or self.button_id == "cog_bug":
|
bug_description = discord.ui.TextInput(
|
||||||
self.cog_name = discord.ui.TextInput(
|
|
||||||
label="What cog is your suggestion for?",
|
|
||||||
placeholder="If unsure, input 'GalaxyCogs'",
|
|
||||||
style=discord.TextStyle.short,
|
|
||||||
required=True,
|
|
||||||
max_length=100
|
|
||||||
)
|
|
||||||
self.input_list.append(self.cog_name)
|
|
||||||
if self.button_id == "cog_suggestion" or self.button_id == "bot_suggestion":
|
|
||||||
self.suggestion_description = discord.ui.TextInput(
|
|
||||||
label="Describe your suggestion.",
|
|
||||||
placeholder="A clear and concise description of what the suggestion is.",
|
|
||||||
style=discord.TextStyle.paragraph,
|
|
||||||
required=True,
|
|
||||||
max_length=2048
|
|
||||||
)
|
|
||||||
self.input_list.append(self.suggestion_description)
|
|
||||||
if self.button_id == "bot_bug" or self.button_id == "cog_bug":
|
|
||||||
self.bug_description = discord.ui.TextInput(
|
|
||||||
label="Describe the bug",
|
label="Describe the bug",
|
||||||
placeholder="A clear and concise description of what the bug is.",
|
placeholder="A clear and concise description of what the bug is.",
|
||||||
style=discord.TextStyle.paragraph,
|
style=discord.TextStyle.paragraph,
|
||||||
required=True,
|
|
||||||
max_length=2048
|
max_length=2048
|
||||||
)
|
)
|
||||||
self.reproduction_steps = discord.ui.TextInput(
|
reproduction_steps = discord.ui.TextInput(
|
||||||
label="To Reproduce",
|
label="To Reproduce",
|
||||||
placeholder="What caused the bug?",
|
placeholder="What caused the bug?",
|
||||||
style=discord.TextStyle.paragraph,
|
style=discord.TextStyle.paragraph,
|
||||||
required=True,
|
required=True,
|
||||||
max_length=2048
|
max_length=2048
|
||||||
)
|
)
|
||||||
self.expected_behavior = discord.ui.TextInput(
|
expected_behavior = discord.ui.TextInput(
|
||||||
label="Expected Behavior",
|
label="Expected Behavior",
|
||||||
placeholder="A clear and concise description of what you expected to happen.",
|
placeholder="A clear and concise description of what you expected to happen.",
|
||||||
style=discord.TextStyle.paragraph,
|
style=discord.TextStyle.paragraph,
|
||||||
required=True,
|
required=True,
|
||||||
max_length=2048
|
max_length=2048
|
||||||
)
|
)
|
||||||
self.input_list.append(self.bug_description)
|
additional_context = discord.ui.TextInput(
|
||||||
self.input_list.append(self.reproduction_steps)
|
|
||||||
self.input_list.append(self.expected_behavior)
|
|
||||||
self.additional_context = discord.ui.TextInput(
|
|
||||||
label="Additional Context",
|
label="Additional Context",
|
||||||
placeholder=f"Add any other context about the {'problem' if self.button_id == 'cog_bug' or self.button_id == 'bot_bug' else 'suggestion'} here.",
|
placeholder="Add any other context about the problem here.",
|
||||||
style=discord.TextStyle.paragraph,
|
style=discord.TextStyle.paragraph,
|
||||||
required=False,
|
required=False,
|
||||||
max_length=2048
|
max_length=2048
|
||||||
)
|
)
|
||||||
self.screenshots = discord.ui.TextInput(
|
|
||||||
label="Screenshots",
|
|
||||||
placeholder=f"Add screenshots to help explain your {'problem' if self.button_id == 'cog_bug' or self.button_id == 'bot_bug' else 'suggestion'}. Seperate each screenshot with a newline.",
|
|
||||||
style=discord.TextStyle.paragraph,
|
|
||||||
required=False,
|
|
||||||
max_length=2048
|
|
||||||
)
|
|
||||||
self.input_list.append(self.additional_context)
|
|
||||||
self.input_list.append(self.screenshots)
|
|
||||||
|
|
||||||
async def on_submit(self, interaction: discord.Interaction):
|
async def on_submit(self, interaction: discord.Interaction):
|
||||||
embed = discord.Embed(title="Issue Request", color=await Issues.bot.get_embed_color(None))
|
embed = discord.Embed(title="Issue Request", color=await Issues.bot.get_embed_color(None))
|
||||||
for item in self.input_list:
|
fields = [self.bug_description, self.reproduction_steps, self.expected_behavior, self.additional_context]
|
||||||
|
for item in fields:
|
||||||
title = item.label
|
title = item.label
|
||||||
value = item.value
|
value = item.value
|
||||||
if value is not None:
|
if value is not None:
|
||||||
embed.add_field(title, value)
|
embed.add_field(title, value)
|
||||||
await interaction.response.send_message(embed=embed)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue