From bb774296cf613c66dc8d2863547c1147e8ad6520 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Tue, 21 Jul 2020 13:28:07 -0700 Subject: Charinfo: use send_denial helper --- bot/cogs/utils.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index 697bf60ce..60e160ed0 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -12,6 +12,7 @@ from discord.ext.commands import BadArgument, Cog, Context, command from bot.bot import Bot from bot.constants import Channels, MODERATION_ROLES, STAFF_ROLES from bot.decorators import in_whitelist, with_role +from bot.utils import messages log = logging.getLogger(__name__) @@ -120,22 +121,15 @@ class Utils(Cog): """Shows you information on up to 25 unicode characters.""" match = re.match(r"<(a?):(\w+):(\d+)>", characters) if match: - embed = Embed( - title="Non-Character Detected", - description=( - "Only unicode characters can be processed, but a custom Discord emoji " - "was found. Please remove it and try again." - ) + return await messages.send_denial( + ctx, + "**Non-Character Detected**\n" + "Only unicode characters can be processed, but a custom Discord emoji " + "was found. Please remove it and try again." ) - embed.colour = Colour.red() - await ctx.send(embed=embed) - return if len(characters) > 25: - embed = Embed(title=f"Too many characters ({len(characters)}/25)") - embed.colour = Colour.red() - await ctx.send(embed=embed) - return + return await messages.send_denial(ctx, f"Too many characters ({len(characters)}/25)") def get_info(char: str) -> Tuple[str, str]: digit = f"{ord(char):x}" -- cgit v1.2.3 From 6c367269032b85fd60094228178209760aa8d282 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Tue, 21 Jul 2020 13:48:21 -0700 Subject: Charinfo: paginate the results Pagination ensures the results will never go over the char limit for an embed. Fixes #897 Fixes BOT-3D --- bot/cogs/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index 60e160ed0..d70fb300d 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -12,6 +12,7 @@ from discord.ext.commands import BadArgument, Cog, Context, command from bot.bot import Bot from bot.constants import Channels, MODERATION_ROLES, STAFF_ROLES from bot.decorators import in_whitelist, with_role +from bot.pagination import LinePaginator from bot.utils import messages log = logging.getLogger(__name__) @@ -142,15 +143,14 @@ class Utils(Cog): info = f"`{u_code.ljust(10)}`: {name} - {utils.escape_markdown(char)}" return info, u_code - charlist, rawlist = zip(*(get_info(c) for c in characters)) - - embed = Embed(description="\n".join(charlist)) - embed.set_author(name="Character Info") + char_list, raw_list = zip(*(get_info(c) for c in characters)) + embed = Embed().set_author(name="Character Info") if len(characters) > 1: - embed.add_field(name='Raw', value=f"`{''.join(rawlist)}`", inline=False) + # Maximum length possible is 252 so no need to truncate. + embed.add_field(name='Raw', value=f"`{''.join(raw_list)}`", inline=False) - await ctx.send(embed=embed) + await LinePaginator.paginate(char_list, ctx, embed, max_size=2000, empty=False) @command() async def zen(self, ctx: Context, *, search_value: Union[int, str, None] = None) -> None: -- cgit v1.2.3 From 14b00ad1fdc065f1f5412a875f31182d4ccfe7a2 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 22 Jul 2020 23:30:53 -0700 Subject: Charinfo: use more descriptive field name Since the raw field is displayed on every page, but pages are incomplete, it may be unclear whether the field's value is for the current page or for all pages. Co-authored-by: Kieran Siek --- bot/cogs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index d70fb300d..8171706d0 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -148,7 +148,7 @@ class Utils(Cog): if len(characters) > 1: # Maximum length possible is 252 so no need to truncate. - embed.add_field(name='Raw', value=f"`{''.join(raw_list)}`", inline=False) + embed.add_field(name='Full Raw Text', value=f"`{''.join(raw_list)}`", inline=False) await LinePaginator.paginate(char_list, ctx, embed, max_size=2000, empty=False) -- cgit v1.2.3 From c35842b30d7bf8c58251ce780c4fe75eaf23a69f Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Wed, 22 Jul 2020 23:35:51 -0700 Subject: Charinfo: up char limit and reduce line limit Pagination means more characters can be supported without cluttering anything. It also means infinite lines, so there's no longer a need to squeeze out the most from a single page. Reducing the line limit leads to a smaller, tidier presentation. --- bot/cogs/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index 8171706d0..c0dc284e4 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -119,7 +119,7 @@ class Utils(Cog): @command() @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_ROLES) async def charinfo(self, ctx: Context, *, characters: str) -> None: - """Shows you information on up to 25 unicode characters.""" + """Shows you information on up to 50 unicode characters.""" match = re.match(r"<(a?):(\w+):(\d+)>", characters) if match: return await messages.send_denial( @@ -129,7 +129,7 @@ class Utils(Cog): "was found. Please remove it and try again." ) - if len(characters) > 25: + if len(characters) > 50: return await messages.send_denial(ctx, f"Too many characters ({len(characters)}/25)") def get_info(char: str) -> Tuple[str, str]: @@ -147,10 +147,10 @@ class Utils(Cog): embed = Embed().set_author(name="Character Info") if len(characters) > 1: - # Maximum length possible is 252 so no need to truncate. + # Maximum length possible is 502 out of 1024, so there's no need to truncate. embed.add_field(name='Full Raw Text', value=f"`{''.join(raw_list)}`", inline=False) - await LinePaginator.paginate(char_list, ctx, embed, max_size=2000, empty=False) + await LinePaginator.paginate(char_list, ctx, embed, max_lines=10, max_size=2000, empty=False) @command() async def zen(self, ctx: Context, *, search_value: Union[int, str, None] = None) -> None: -- cgit v1.2.3 From e15ceb83ac0ac081325ee47b1f6dddc581229197 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 22 Jul 2020 23:46:51 -0700 Subject: Charinfo: correct char limit used in error message Co-authored-by: Kieran Siek --- bot/cogs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index c0dc284e4..017f3419e 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -130,7 +130,7 @@ class Utils(Cog): ) if len(characters) > 50: - return await messages.send_denial(ctx, f"Too many characters ({len(characters)}/25)") + return await messages.send_denial(ctx, f"Too many characters ({len(characters)}/50)") def get_info(char: str) -> Tuple[str, str]: digit = f"{ord(char):x}" -- cgit v1.2.3