From 145af384ededb05ad1e2e11733d3aa53495312fb Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Sun, 28 Jun 2020 00:24:54 -0400 Subject: In LinePaginator, add limit of 2000 for max_size and scale_to_size args --- bot/cogs/help.py | 2 +- bot/pagination.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bot/cogs/help.py b/bot/cogs/help.py index 542f19139..f59d30c9a 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -299,7 +299,7 @@ class CustomHelpCommand(HelpCommand): embed, prefix=description, max_lines=COMMANDS_PER_PAGE, - max_size=2040, + max_size=2000, ) async def send_bot_help(self, mapping: dict) -> None: diff --git a/bot/pagination.py b/bot/pagination.py index 34ce7317b..97ef08ad6 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -58,10 +58,20 @@ class LinePaginator(Paginator): """ self.prefix = prefix self.suffix = suffix + + # Embeds that exceed 2048 characters will result in an HTTPException + # (Discord API limit), so we've set a limit of 2000 + if max_size > 2000: + raise ValueError(f"max_size must be <= 2,000 characters. ({max_size} > 2000)") + self.max_size = max_size - len(suffix) + if scale_to_size < max_size: raise ValueError(f"scale_to_size must be >= max_size. ({scale_to_size} < {max_size})") + if scale_to_size > 2000: + raise ValueError(f"max_size must be <= 2,000 characters. ({scale_to_size} > 2000)") + self.scale_to_size = scale_to_size - len(suffix) self.max_lines = max_lines self._current_page = [prefix] -- cgit v1.2.3