Skip to content

Commit

Permalink
Fix error when URL is too large #30
Browse files Browse the repository at this point in the history
  • Loading branch information
timraay committed Dec 15, 2024
1 parent a08cd31 commit fbca7b3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions barricade/discord/views/report_management.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from datetime import datetime, timezone
from io import BytesIO
import re

import discord
from discord import ButtonStyle, Interaction
Expand Down Expand Up @@ -92,10 +93,22 @@ async def confirm_delete(_interaction: Interaction):
db_report.token.expires_at = datetime.now(tz=timezone.utc) + REPORT_TOKEN_EXPIRE_DELTA
# Send URL to user
url = get_report_edit_url(schemas.ReportWithToken.model_validate(db_report))
await interaction.response.send_message(
content="## " + format_url("Open Google Form", url),
ephemeral=True
)
body = "## " + format_url("Open Google Form", url)

if len(body) <= 4096:
await interaction.response.send_message(
embed=discord.Embed(description=body),
ephemeral=True
)
else:
fp = BytesIO(url.encode())
fp.seek(0)
file = discord.File(fp, "url.txt")
await interaction.response.send_message(
content="The URL was too large, so it has been uploaded as a file instead.",
file=file,
ephemeral=True
)

case _:
raise ValueError("Unknown command %s" % self.command)
Expand Down

0 comments on commit fbca7b3

Please sign in to comment.