diff options
author | 2021-02-23 03:48:35 +0100 | |
---|---|---|
committer | 2021-02-23 03:48:35 +0100 | |
commit | 0b11d7dfb408f4e5fe6248ae8377ddc7aa1aa5ee (patch) | |
tree | fe44ac67f16db3cf89cf9994d6fd9f03abf1ecab | |
parent | Update max available channels to 3 (diff) |
Add truncate_message util
-rw-r--r-- | bot/utils/messages.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 077dd9569..c01fa5d0e 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -154,3 +154,12 @@ 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 |