macro: Add paging for list_macros() (#55)

* macro: Add paging for list_macros()

* Apply black formatting
This commit is contained in:
TSRBerry 2023-05-28 10:36:37 +02:00 committed by GitHub
parent fa431c1d4c
commit 8f25f13eff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -132,9 +132,19 @@ class Macro(Cog):
async def list_macros(self, ctx: Context, macros_only=False): async def list_macros(self, ctx: Context, macros_only=False):
macros = get_macros_dict(self.bot) macros = get_macros_dict(self.bot)
if len(macros["macros"]) > 0: if len(macros["macros"]) > 0:
message = "📝 **Macros**:\n" messages = []
num_messages = (
len(macros["macros"]) // 50 if len(macros["macros"]) > 50 else 1
)
message = ""
for key in sorted(macros["macros"].keys()): for index, key in zip(
range(len(macros["macros"])), sorted(macros["macros"].keys())
):
if index == 0 or index + 1 % 50 == 0:
if len(message) > 0:
messages.append(message)
message = f"📝 **Macros** ({len(messages) + 1}/{num_messages}):\n"
message += f"- {key}\n" message += f"- {key}\n"
if not macros_only and key in macros["aliases"].keys(): if not macros_only and key in macros["aliases"].keys():
message += " - __aliases__: " message += " - __aliases__: "
@ -147,7 +157,11 @@ class Macro(Cog):
message += f", {alias}" message += f", {alias}"
message += "\n" message += "\n"
await ctx.send(message) # Add the last message as well
messages.append(message)
for msg in messages:
await ctx.send(msg)
else: else:
await ctx.send("Couldn't find any macros.") await ctx.send("Couldn't find any macros.")