From 2a19f151fccabb5068ef7f5bcaede14b1b89c783 Mon Sep 17 00:00:00 2001 From: zephyrkul Date: Mon, 14 Aug 2017 22:42:48 -0600 Subject: [PATCH] [Core V3] Fix pagify bug (#920) * Let's try this again... * accidentally a colon --- core/utils/chat_formatting.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/utils/chat_formatting.py b/core/utils/chat_formatting.py index 964a5ec37..19d2ab84c 100644 --- a/core/utils/chat_formatting.py +++ b/core/utils/chat_formatting.py @@ -35,25 +35,28 @@ def pagify(text, delims=["\n"], *, escape_mass_mentions=True, shorten_by=8, page_length=2000): """DOES NOT RESPECT MARKDOWN BOXES OR INLINE CODE""" in_text = text - if escape_mass_mentions: - num_mentions = text.count("@here") + text.count("@everyone") - shorten_by += num_mentions page_length -= shorten_by while len(in_text) > page_length: - closest_delim = max([in_text.rfind(d, 0, page_length) + this_page_len = page_length + if escape_mass_mentions: + this_page_len -= (in_text.count("@here", 0, page_length) + + in_text.count("@everyone", 0, page_length)) + closest_delim = max([in_text.rfind(d, 1, this_page_len) for d in delims]) - closest_delim = closest_delim if closest_delim != -1 else page_length + closest_delim = closest_delim if closest_delim != -1 else this_page_length if escape_mass_mentions: to_send = escape(in_text[:closest_delim], mass_mentions=True) else: to_send = in_text[:closest_delim] - yield to_send + if len(to_send.strip()) > 0: + yield to_send in_text = in_text[closest_delim:] - if escape_mass_mentions: - yield escape(in_text, mass_mentions=True) - else: - yield in_text + if len(in_text.strip()) > 0: + if escape_mass_mentions: + yield escape(in_text, mass_mentions=True) + else: + yield in_text def strikethrough(text):