fix(issues): added proper handling for if a string is longer than 1024 characters
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
parent
ff1b942d8c
commit
854935da7e
1 changed files with 18 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
import asyncio
|
||||
import aiohttp
|
||||
import discord
|
||||
from discord.interactions import Interaction
|
||||
from redbot.core import Config, app_commands, commands
|
||||
from redbot.core import Config, app_commands, commands, checks
|
||||
|
||||
|
||||
class Issues(commands.Cog):
|
||||
"""This cog allows you to create Gitea issues through a Discord modal.
|
||||
|
@ -16,6 +19,7 @@ class Issues(commands.Cog):
|
|||
)
|
||||
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
async def issuesconfig(self, ctx: commands.Context, channel: discord.TextChannel = None):
|
||||
if channel:
|
||||
await self.config.request_channel.set(channel.id)
|
||||
|
@ -107,12 +111,18 @@ class Issues(commands.Cog):
|
|||
title = item.label
|
||||
value = item.value
|
||||
if value is not None:
|
||||
if len(value) > 1024:
|
||||
split_value = [value[i:i+1024] for i in range(0, len(value), 1024)]
|
||||
for i, part in enumerate(split_value):
|
||||
embed.add_field(name=title if i == 0 else "\u200b", value=part, inline=False)
|
||||
else:
|
||||
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)
|
||||
embed.set_author(name="Bot Bug Report")
|
||||
await self.cog_instance.submit_issue_request(interaction=interaction, original_interaction=self.original_interaction, embed=embed)
|
||||
|
||||
class IssueConfigurationButton(discord.ui.View):
|
||||
|
@ -185,6 +195,8 @@ class Issues(commands.Cog):
|
|||
async def on_submit(self,interaction: discord.Interaction):
|
||||
message: discord.Message = await self.channel.fetch_message(self.message_id)
|
||||
embed = message.embeds[0]
|
||||
field_values = []
|
||||
field_names = []
|
||||
if self.approved:
|
||||
embed.color = 1226519
|
||||
embed.title = "Issue Request Approved"
|
||||
|
@ -195,5 +207,9 @@ class Issues(commands.Cog):
|
|||
await interaction.response.send_message(content="Issue request denied.", ephemeral=True)
|
||||
if self.response.value is not None:
|
||||
embed.add_field(name=f"Response from {interaction.user.name}", value=self.response.value, inline=False)
|
||||
for field in embed.fields:
|
||||
if field.name != "\u200b":
|
||||
field_names.append(field.name)
|
||||
field_values.append(field.value)
|
||||
await message.edit(embed=embed, view=None)
|
||||
await self.user.send(embed=embed)
|
||||
|
|
Loading…
Reference in a new issue