mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-23 15:35:47 +02:00
List memes
This commit is contained in:
parent
6cfe788df5
commit
00a146cb2b
5 changed files with 48 additions and 3 deletions
|
|
@ -22,7 +22,7 @@ class BookmarkSource(PageSource[Bookmark]):
|
|||
|
||||
description = ""
|
||||
|
||||
for bookmark in self.dataset[page : page + self.per_page]:
|
||||
for bookmark in self.get_page_data(page):
|
||||
description += f"`#{bookmark.bookmark_id}`: [{bookmark.label}]({bookmark.jump_url})\n"
|
||||
|
||||
embed.description = description.strip()
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ class PageSource(ABC, Generic[T]):
|
|||
"""Method that builds the list of embeds from the input data"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_page_data(self, page: int) -> list[T]:
|
||||
"""Get the chunk of the dataset for page [page]"""
|
||||
return self.dataset[page : page + self.per_page]
|
||||
|
||||
|
||||
class Menu(discord.ui.View):
|
||||
"""Base class for a menu"""
|
||||
|
|
|
|||
27
didier/menus/memes.py
Normal file
27
didier/menus/memes.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from overrides import overrides
|
||||
|
||||
from database.schemas import MemeTemplate
|
||||
from didier.menus.common import PageSource
|
||||
|
||||
__all__ = ["MemeSource"]
|
||||
|
||||
|
||||
class MemeSource(PageSource[MemeTemplate]):
|
||||
"""PageSource for meme templates"""
|
||||
|
||||
@overrides
|
||||
def create_embeds(self, ctx: commands.Context):
|
||||
for page in range(self.page_count):
|
||||
# The colour of the embed is (69,4,20) with the values +100 because they were too dark
|
||||
embed = discord.Embed(title="Meme Templates", colour=discord.Colour.from_rgb(169, 14, 120))
|
||||
|
||||
description_data = []
|
||||
for template in self.get_page_data(page):
|
||||
description_data.append(f"{template.name} ({template.field_count})")
|
||||
|
||||
embed.description = "\n".join(description_data)
|
||||
embed.set_footer(text="Format: Template Name (Field Count)")
|
||||
|
||||
self.embeds.append(embed)
|
||||
Loading…
Add table
Add a link
Reference in a new issue