From 854935da7e91637c1ee3f72fe7fda40cdc77d9e0 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 19 Aug 2023 16:54:55 -0400 Subject: [PATCH] fix(issues): added proper handling for if a string is longer than 1024 characters --- issues/issues.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/issues/issues.py b/issues/issues.py index 55001c7..323971c 100644 --- a/issues/issues.py +++ b/issues/issues.py @@ -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: - embed.add_field(name=title, value=value, inline=False) + 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)