2023-08-17 02:50:25 -04:00
from typing import Union
2023-08-17 02:56:50 -04:00
from redbot . core import commands , Config , app_commands
2023-08-17 02:50:25 -04:00
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 )
2023-08-17 02:56:50 -04:00
self . config . register_global (
2023-08-17 02:50:25 -04:00
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 13:13:01 -04:00
passed_info = interaction
await interaction . response . send_message ( content = " Hello world! " , view = self . IssueButtons ( passed_info ) , ephemeral = True )
2023-08-17 02:50:25 -04:00
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 } ! \n Message contents: \n ``` { message } ``` \n ``` { secondary_message } ``` " , ephemeral = True )
else :
await interaction . response . send_message ( content = f " Message sent to { target . mention } ! \n Message 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 ) :
2023-08-18 13:13:01 -04:00
def __init__ ( self , passed_info ) :
2023-08-17 02:50:25 -04:00
super ( ) . __init__ ( )
2023-08-18 13:13:01 -04:00
self . passed_info : discord . Interaction = passed_info
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 14:17:11 -04:00
await interaction . response . send_modal ( Issues . IssuesModal ( button_id = " bug " ) )
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 14:17:11 -04:00
await interaction . response . send_modal ( Issues . IssuesModal ( button_id = " bug " ) )
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 14:17:11 -04:00
await interaction . response . send_modal ( Issues . IssuesModal ( button_id = " bot_suggestion " ) )
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 14:17:11 -04:00
await interaction . response . send_modal ( Issues . IssuesModal ( button_id = " cog_suggestion " ) )
2023-08-17 02:50:25 -04:00
2023-08-18 14:17:11 -04:00
class IssuesModal ( discord . ui . Modal , title = " Creating issue... " ) :
def __init__ ( self , button_id ) :
2023-08-17 02:56:50 -04:00
super ( ) . __init__ ( )
2023-08-18 14:17:11 -04:00
self . button_id = button_id
self . input_list = [ ]
2023-08-17 02:56:50 -04:00
2023-08-18 14:17:11 -04:00
if self . button_id == " cog_suggestion " :
self . cog_name = discord . ui . TextInput (
2023-08-18 14:21:18 -04:00
label = " What cog is your suggestion for? " ,
2023-08-18 14:17:11 -04:00
placeholder = " If unsure, input ' GalaxyCogs ' " ,
style = discord . TextStyle . short ,
max_length = 100
)
self . input_list . append ( self . cog_name )
if self . button_id == " cog_suggestion " or self . button_id == " bot_suggestion " :
2023-08-18 14:21:18 -04:00
self . suggestion_description = discord . ui . TextInput (
label = " Describe your suggestion. " ,
placeholder = " A clear and concise description of what the suggestion is. " ,
2023-08-18 14:17:11 -04:00
style = discord . TextStyle . paragraph ,
max_length = 2048
)
2023-08-18 14:21:18 -04:00
self . input_list . append ( self . suggestion_description )
if self . button_id == " bug " :
2023-08-18 14:17:11 -04:00
self . 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
)
self . reproduction_steps = discord . ui . TextInput (
label = " To Reproduce " ,
placeholder = " What caused the bug? " ,
style = discord . TextStyle . paragraph ,
required = True ,
max_length = 2048
)
self . 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
)
self . input_list . append ( self . bug_description )
self . input_list . append ( self . reproduction_steps )
self . input_list . append ( self . expected_behavior )
self . additional_context = discord . ui . TextInput (
label = " Additional Context " ,
placeholder = f " Add any other context about the { ' problem ' if self . button_id == ' bug ' else ' feature request ' } here. " ,
style = discord . TextStyle . paragraph ,
required = False ,
max_length = 2048
)
self . screenshots = discord . ui . TextInput (
label = " Screenshots " ,
placeholder = f " Add screenshots to help explain your { ' problem ' if self . button_id == ' bug ' else ' feature request ' } . 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 )
2023-08-17 02:50:25 -04:00
async def on_submit ( self , interaction : discord . Interaction ) :
embed = discord . Embed ( title = " Issue Request " , color = await Issues . bot . get_embed_color ( None ) )
2023-08-18 14:17:11 -04:00
for item in self . input_list :
title = item . label
value = item . value
if value is not None :
embed . add_field ( title , value )
await interaction . response . send_message ( embed = embed )