feat(issues): implemented submit_issue_request
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 5s

This commit is contained in:
Seaswimmer 2023-08-18 14:46:24 -04:00
parent 83b7c3f17e
commit 246242ad71
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -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):
@ -98,4 +89,9 @@ class Issues(commands.Cog):
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)