From 90b8a8fb8b5a32169ddc1d331eaa38d9c6bf270e Mon Sep 17 00:00:00 2001 From: Numerlor Date: Tue, 31 Dec 2019 23:51:46 +0100 Subject: Make sure description is truncated to max 1000 chars --- bot/cogs/doc.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot/cogs/doc.py b/bot/cogs/doc.py index 9506b195a..c1bb4ad41 100644 --- a/bot/cogs/doc.py +++ b/bot/cogs/doc.py @@ -307,8 +307,15 @@ class Doc(commands.Cog): if len(description) > 1000: shortened = description[:1000] last_paragraph_end = shortened.rfind('\n\n', 100) + # Search the shortened version for cutoff points in decreasing desirability, + # cutoff at 1000 if none are found. if last_paragraph_end == -1: - last_paragraph_end = shortened.rfind('. ') + for string in (". ", ", ", ",", " "): + last_paragraph_end = shortened.rfind(string) + if last_paragraph_end != -1: + break + else: + last_paragraph_end = 1000 description = description[:last_paragraph_end] # If there is an incomplete code block, cut it out @@ -318,7 +325,6 @@ class Doc(commands.Cog): description += f"... [read more]({permalink})" description = WHITESPACE_AFTER_NEWLINES_RE.sub('', description) - if signatures is None: # If symbol is a module, don't show signature. embed_description = description -- cgit v1.2.3 From 2b032a35fa64e770678b051c164dbfc53ef56893 Mon Sep 17 00:00:00 2001 From: Numerlor Date: Wed, 1 Jan 2020 00:43:03 +0100 Subject: Rename last_paragraph_end variable to a more fitting name --- bot/cogs/doc.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bot/cogs/doc.py b/bot/cogs/doc.py index c1bb4ad41..16a690f39 100644 --- a/bot/cogs/doc.py +++ b/bot/cogs/doc.py @@ -306,17 +306,17 @@ class Doc(commands.Cog): # of a double newline (interpreted as a paragraph) before index 1000. if len(description) > 1000: shortened = description[:1000] - last_paragraph_end = shortened.rfind('\n\n', 100) + description_cutoff = shortened.rfind('\n\n', 100) # Search the shortened version for cutoff points in decreasing desirability, # cutoff at 1000 if none are found. - if last_paragraph_end == -1: + if description_cutoff == -1: for string in (". ", ", ", ",", " "): - last_paragraph_end = shortened.rfind(string) - if last_paragraph_end != -1: + description_cutoff = shortened.rfind(string) + if description_cutoff != -1: break else: - last_paragraph_end = 1000 - description = description[:last_paragraph_end] + description_cutoff = 1000 + description = description[:description_cutoff] # If there is an incomplete code block, cut it out if description.count("```") % 2: -- cgit v1.2.3 From 1da2c04e43551cf36646c85880647aa33c40cb24 Mon Sep 17 00:00:00 2001 From: Numerlor Date: Wed, 1 Jan 2020 00:43:33 +0100 Subject: Move comment into if body --- bot/cogs/doc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/doc.py b/bot/cogs/doc.py index 16a690f39..cb6f4f972 100644 --- a/bot/cogs/doc.py +++ b/bot/cogs/doc.py @@ -307,9 +307,9 @@ class Doc(commands.Cog): if len(description) > 1000: shortened = description[:1000] description_cutoff = shortened.rfind('\n\n', 100) - # Search the shortened version for cutoff points in decreasing desirability, - # cutoff at 1000 if none are found. if description_cutoff == -1: + # Search the shortened version for cutoff points in decreasing desirability, + # cutoff at 1000 if none are found. for string in (". ", ", ", ",", " "): description_cutoff = shortened.rfind(string) if description_cutoff != -1: -- cgit v1.2.3