Modlog account for very long case reasons (#4541)

* Modlog account for very long case reasons

* if
This commit is contained in:
TrustyJAID 2020-10-26 19:12:06 -06:00 committed by GitHub
parent b30a8b86a4
commit 085cd1bb49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,7 @@ from .utils.common_filters import (
filter_urls,
escape_spoilers,
)
from .utils.chat_formatting import pagify
from .i18n import Translator, set_contextual_locales_from_guild
from .generic_casetypes import all_generics
@ -342,11 +343,7 @@ class Case:
title = "{}".format(
_("Case #{} | {} {}").format(self.case_number, casetype.case_str, casetype.image)
)
if self.reason:
reason = _("**Reason:** {}").format(self.reason)
else:
reason = _("**Reason:** Use the `reason` command to add it")
reason = _("**Reason:** Use the `reason` command to add it")
if self.moderator is None:
moderator = _("Unknown")
@ -403,6 +400,19 @@ class Case:
) # Invites and spoilers get rendered even in embeds.
if embed:
if self.reason:
reason = _("**Reason:** {}").format(self.reason)
if len(reason) > 2048:
reason = (
next(
pagify(
reason,
delims=[" ", "\n"],
page_length=2000,
)
)
+ "..."
)
emb = discord.Embed(title=title, description=reason)
emb.set_author(name=user)
emb.add_field(name=_("Moderator"), value=moderator, inline=False)
@ -425,6 +435,19 @@ class Case:
emb.timestamp = datetime.utcfromtimestamp(self.created_at)
return emb
else:
if self.reason:
reason = _("**Reason:** {}").format(self.reason)
if len(reason) > 1000:
reason = (
next(
pagify(
reason,
delims=[" ", "\n"],
page_length=1000,
)
)
+ "..."
)
user = filter_mass_mentions(filter_urls(user)) # Further sanitization outside embeds
case_text = ""
case_text += "{}\n".format(title)