feat(issues): added new cog
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 17s

This commit is contained in:
SeaswimmerTheFsh 2023-08-17 02:50:25 -04:00
parent aa501a0f14
commit 52752f06b5
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8
3 changed files with 99 additions and 0 deletions

5
issues/__init__.py Normal file
View file

@ -0,0 +1,5 @@
from .issues import Issues
async def setup(bot):
await bot.add_cog(Issues(bot))

8
issues/info.json Normal file
View file

@ -0,0 +1,8 @@
{
"author" : ["SeaswimmerTheFsh"],
"install_msg" : "Thank you for installing Issues!\nYou can find the source code of this cog here: https://git.seaswimmer.cc/SeaswimmerTheFsh/GalaxyCogs",
"name" : "Issues",
"short" : "This cog allows you to create Gitea issues through a Discord modal.",
"description" : "This cog allows you to create Gitea issues through a Discord modal.",
"end_user_data_statement" : "This cog does not store any End User Data."
}

86
issues/issues.py Normal file
View file

@ -0,0 +1,86 @@
from typing import Union
from redbot.core import commands, Config
import discord
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_guild(
channel = None,
)
@commands.command()
async def issuestest(self, ctx: commands.Context):
await ctx.message.reply(content="Hello world!", view=self.IssueButtons)
async def send_to_target(self, target: Union[discord.Member, discord.TextChannel], interaction: discord.Interaction, message: str, secondary_message: str = None):
if isinstance(target, discord.Member):
target_type = "member"
elif isinstance(target, discord.TextChannel):
target_type = "textchannel"
try:
await target.send(message)
if secondary_message is not None:
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:
if target_type == "member":
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):
def __init__(self, timeout):
super().__init__()
self.timeout = timeout
@discord.ui.button(label="Yes", style=discord.ButtonStyle.success)
async def issue_button_bot(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.response.send_modal(Issues.BotModal())
class BotModal(discord.ui.Modal, title="Creating issue..."):
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
)
screenshots = discord.ui.TextInput(
label="Screenshots",
placeholder="If applicable, add screenshots to help explain your problem. Seperate each screenshot with a newline.",
style=discord.TextStyle.paragraph,
required=False,
max_length=2048
)
async def on_submit(self, interaction: discord.Interaction):
embed = discord.Embed(title="Issue Request", color=await Issues.bot.get_embed_color(None))
fields = [self.description, self.reproduction_steps, self.expected_behavior, self.additional_context, self.screenshots]
await Issues.send_to_target(self, self.target, interaction, self.message, self.secondary_message)