Skip to content

Commit

Permalink
Improve snippet listing
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed Jul 7, 2024
1 parent d4500de commit 47aada1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import re
from datetime import timezone
from itertools import zip_longest
from typing import List, Literal, Optional, Tuple, Union

import discord
Expand Down Expand Up @@ -160,13 +159,18 @@ async def snippet(self, ctx, *, name: str.lower = None):
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild, size=128))
return await ctx.send(embed=embed)

embeds = []

for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)):
description = format_description(i, names)
embed = discord.Embed(color=self.bot.main_color, description=description)
embeds, i = [], 0
embed = discord.Embed(color=self.bot.main_color)
for name, content in zip(self.bot.snippets.keys(), self.bot.snippets.values()):
if i % 10 == 0:
embed = discord.Embed(color=self.bot.main_color)
embed.add_field(
name=name, value=f"{content[:127]}{'...' if len(content) > 128 else ''}", inline=False
)
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild, size=128))
embeds.append(embed)
if i % 10 == 0:
embeds.append(embed)
i += 1

session = EmbedPaginatorSession(ctx, *embeds)
await session.run()
Expand Down

0 comments on commit 47aada1

Please sign in to comment.