aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gustav Odinger <[email protected]>2021-02-23 11:14:31 +0100
committerGravatar Gustav Odinger <[email protected]>2021-02-23 11:14:31 +0100
commitcae0d84757e026976f1a9e87d52c581669b7b8e8 (patch)
treeaac8969c16934b533e484812568d29ee33541214
parentUpdate embed field title to be more formal (diff)
Use textwrap.shorten instead of custom function
This applies to the help channel DM embed, where the user is sent a truncated version of their message.
-rw-r--r--bot/exts/help_channels/_message.py6
-rw-r--r--bot/utils/messages.py9
2 files changed, 4 insertions, 11 deletions
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
index 95aca067a..4113e51c5 100644
--- a/bot/exts/help_channels/_message.py
+++ b/bot/exts/help_channels/_message.py
@@ -1,4 +1,5 @@
import logging
+import textwrap
import typing as t
from datetime import datetime
@@ -8,7 +9,6 @@ import bot
from bot import constants
from bot.exts.help_channels import _caches
from bot.utils.channel import is_in_category
-from bot.utils.messages import truncate_message
log = logging.getLogger(__name__)
@@ -108,7 +108,9 @@ async def dm_on_open(message: discord.Message) -> None:
embed.set_thumbnail(url=constants.Icons.green_questionmark)
embed.add_field(
- name="Your message", value=truncate_message(message, limit=100), inline=False
+ name="Your message",
+ value=textwrap.shorten(message.content, width=100, placeholder="..."),
+ inline=False,
)
embed.add_field(
name="Conversation",
diff --git a/bot/utils/messages.py b/bot/utils/messages.py
index c01fa5d0e..077dd9569 100644
--- a/bot/utils/messages.py
+++ b/bot/utils/messages.py
@@ -154,12 +154,3 @@ async def send_denial(ctx: Context, reason: str) -> None:
def format_user(user: discord.abc.User) -> str:
"""Return a string for `user` which has their mention and ID."""
return f"{user.mention} (`{user.id}`)"
-
-
-def truncate_message(message: discord.Message, limit: int) -> str:
- """Returns a truncated version of the message content, up to the specified limit."""
- text = message.content
- if len(text) > limit:
- return text[:limit-3] + "..."
- else:
- return text