async def leaderboard(self, inter: disnake.ApplicationCommandInteraction, start: int = 1): if not await self.validate_leaderboard_offset(start, inter): return embed = disnake.Embed() value_num = math.ceil(start / config.karma_grillbot_leaderboard_size) value = messages.karma_web if value_num == 1 else f"{messages.karma_web}{value_num}" embed.add_field(name=messages.karma_web_title, value=value) page_source = LeaderboardPageSource( bot=self.bot, author=inter.author, query=karma_r.leaderboard_query(Database_karma.karma.desc()), row_formatter=self._leaderboard_formatter, base_embed=embed, title='KARMA LEADERBOARD', emote_name='trophy', member_id_col_name='member_ID', ) page_num = math.floor(start / page_source.per_page) page = page_source.get_page(page_num) embed = page_source.format_page(page) await self.check.botroom_check(inter) view = EmbedView(embeds=[embed], page_source=page_source) view.message = await inter.response.send_message(embed=embed, view=view)
async def huggers(self, ctx: commands.Context): """ Get the biggest huggers. """ async with ctx.typing(): page_source = LeaderboardPageSource( bot=self.bot, author=ctx.author, query=self.hugs_repo.get_top_givers_query(), row_formatter=self._tophuggers_formatter, title='TOP HUGGERS', emote_name='peepoHugger') page = page_source.get_page(0) embed = page_source.format_page(page) await self.check.botroom_check(ctx.message) view = EmbedView(embeds=[embed], page_source=page_source) view.message = await ctx.send(embed=embed, view=view)
async def hugboard(self, ctx: commands.Context): """ Overall hugging stats. """ async with ctx.typing(): page_source = LeaderboardPageSource( bot=self.bot, author=ctx.author, query=self.hugs_repo.get_top_all_query(), row_formatter=_tophugs_formatter, title='HUGBOARD', emote_name='peepoHugger', ) page = page_source.get_page(0) embed = page_source.format_page(page) await self.check.botroom_check(ctx.message) view = EmbedView(embeds=[embed], page_source=page_source) view.message = await ctx.send(embed=embed, view=view)
def __init__(self, embeds: List[disnake.Embed], row: int = 1, author: int = 0, roll_arroud: bool = True, end_arrow: bool = True, page_source: LeaderboardPageSource = None, timeout: int = 300): """Embed pagination view param: List[disnake.Embed] embeds: List of embed to be paginated param int row: On which row should be buttons added, defaults to first param int author: If presented allow just message autor to change pages param bool roll_arroud: After last page rollaround to first param bool end_arrow: If true use also '⏩' button param LeaderboardPageSource page_source: Use for long leaderboards, embeds should contain one embed param int timeout: Seconds until disabling interaction, use None for always enabled """ self.page = 1 self.page_source = page_source self.roll_arroud = roll_arroud self.author = author if self.page_source is None: self.max_page = len(embeds) else: self.max_page = page_source.get_max_pages() end_arrow = False self.embeds = embeds super().__init__(timeout=timeout) if self.max_page <= 1: return self.add_item( disnake.ui.Button(emoji="⏪", custom_id="embed:start_page", row=row, style=disnake.ButtonStyle.primary)) self.add_item( disnake.ui.Button(emoji="◀", custom_id="embed:prev_page", row=row, style=disnake.ButtonStyle.primary)) self.add_item( disnake.ui.Button(emoji="▶", custom_id="embed:next_page", row=row, style=disnake.ButtonStyle.primary)) if end_arrow: self.add_item( disnake.ui.Button(emoji="⏩", custom_id="embed:end_page", row=row, style=disnake.ButtonStyle.primary))
async def ishaboard(self, inter: disnake.ApplicationCommandInteraction, start: int = 1): if not await self.validate_leaderboard_offset(start, inter): return page_source = LeaderboardPageSource( bot=self.bot, author=inter.author, query=karma_r.leaderboard_query(Database_karma.negative.desc()), row_formatter=self._negative_formatter, title='KARMA ISHABOARD', emote_name='ishagrin', member_id_col_name='member_ID', ) page_num = math.floor(start / page_source.per_page) page = page_source.get_page(page_num) embed = page_source.format_page(page) await self.check.botroom_check(inter) view = EmbedView(embeds=[embed], page_source=page_source) view.message = await inter.response.send_message(embed=embed, view=view)