Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix(wormhole): Text limit #271

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions plugins/wormhole/wormhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ async def send_message(
thread: discord.Thread = None,
):
"Send a message into a wormhole entry"
msg_content = []
if len(msg.content) > 2000:
msg_content.append(msg.content[:2000])
msg_content.append(msg.content[2000:])
else:
msg_content.append(msg.content)

files = []
for attachment in msg.attachments:
file = await attachment.to_file()
Expand All @@ -81,7 +88,7 @@ async def send_message(
)
avatar_url = msg.author.display_avatar
if pp_guild:
avatar_url = msg.guild.icon_url
avatar_url = msg.guild.icon.url

embeds = [embed for embed in msg.embeds if embed.type == "rich"]
if embed_reply and embeds:
Expand All @@ -93,8 +100,8 @@ async def send_message(

if thread is None:
new_msg: discord.WebhookMessage = await webhook.send(
content=msg.content,
files=files,
content=msg_content[0],
files=files if len(msg_content) == 1 else [],
embeds=embeds,
avatar_url=avatar_url,
username=username,
Expand All @@ -103,8 +110,8 @@ async def send_message(
)
else:
new_msg: discord.WebhookMessage = await webhook.send(
content=msg.content,
files=files,
content=msg_content[0],
files=files if len(msg_content) == 1 else [],
embeds=embeds,
thread=thread,
avatar_url=avatar_url,
Expand All @@ -116,6 +123,19 @@ async def send_message(
if mentions.roles or mentions.users or mentions.everyone:
await new_msg.edit(allowed_mentions=mentions)

# If the length of the message is longer than 2000 characters, we will split it
# Since nitro allows for a max of 4000 characters, it should be fine
if len(msg.content) > 2000:
await webhook.send(
content=msg_content[1],
avatar_url=msg.author.display_avatar,
files=files,
username=username,
allowed_mentions=discord.AllowedMentions.none(),
wait=True,
)



class PermissionType(commands.Converter):
"Represents a wormhole entry permission (ie. write, read or both)"
Expand Down
Loading