async def pushboard_edit(self, ctx): """Edit the format of the guild's pushboard""" table = CLYTable() table.add_rows([[0, 4721, 56, "Rowcoy"], [1, 4709, 42, "Stitch"], [2, 4658, 37, "t3pps"]]) table.title = "**Option 1 Example**" option_1_render = f"**Option 1 Example**\n{table.render_option_1()}" table.clear_rows() table.add_rows([[0, 4721, "Rowcoy (Awesome Clan)"], [1, 4709, "Stitch (Lilo's Clan)"], [2, 4658, "t3pps (Other Clan)"]]) option_2_render = f"**Option 2 Example**\n{table.render_option_2()}" embed = discord.Embed(color=self.bot.color) fmt = (f"{option_1_render}\n\n{option_2_render}\n\n\n" f"These are the 2 available options.\n" f"Please click the reaction of the format you \n" f"wish to display on your pushboard.") embed.description = fmt msg = await ctx.send(embed=embed) sql = "UPDATE guilds SET pushboard_render = $1 WHERE guild_id = $2" reactions = ["1\N{combining enclosing keycap}", "2\N{combining enclosing keycap}"] for r in reactions: await msg.add_reaction(r) def check(r, u): return str(r) in reactions and u.id == ctx.author.id and r.message.id == msg.id try: r,u = await self.bot.wait_for("reaction_add", check=check, timeout=60.0) except asyncio.TimeoutError: await ctx.db.execute(sql, 1, ctx.guild.id) return await ctx.send("I got bored waiting and selected Option 1 for you.") await ctx.db.execute(sql, reactions.index(str(r)) + 1, ctx.guild.id) await ctx.confirm() await ctx.send("All done. Thank you!") self.get_guild_config.invalidate(self, ctx.guild.id)
class TablePaginator(Pages): def __init__(self, ctx, data, title=None, page_count=1, rows_per_table=20, description=''): super().__init__(ctx, entries=[i for i in range(page_count)], per_page=1) self.table = CLYTable() self.data = [(i, v) for (i, v) in enumerate(data)] self.entries = [None for _ in range(page_count)] self.rows_per_table = rows_per_table self.title = title self.message = None self.ctx = ctx self.description = description if getattr(ctx, 'config', None): try: self.icon_url = ctx.config.icon_url or ctx.guild.icon_url self.title = ctx.config.title or title except AttributeError: self.icon_url = ctx.guild.icon_url else: self.icon_url = ctx.guild.icon_url async def get_page(self, page): try: entry = self.entries[page - 1] if entry: return entry except IndexError: pass if not self.message: self.message = await self.channel.send('Loading...') else: await self.message.edit(content='Loading...', embed=None) entry = await self.prepare_entry(page) self.entries[page - 1] = entry return self.entries[page - 1] async def prepare_entry(self, page): self.table.clear_rows() base = (page - 1) * self.rows_per_table data = self.data[base:base + self.rows_per_table] for n in data: self.table.add_row(n) render = get_render_type(self.ctx.config, self.table) return render() async def get_embed(self, entries, page, *, first=False): if self.maximum_pages > 1: if self.show_entry_count: text = f'Page {page}/{self.maximum_pages} ({len(self.entries)} entries)' else: text = f'Page {page}/{self.maximum_pages}' self.embed.set_footer(text=text) self.embed.description = self.description + entries self.embed.set_author( name=textwrap.shorten(self.title, width=240, placeholder='...'), icon_url=self.icon_url ) return self.embed async def show_page(self, page, *, first=False): self.current_page = page entries = await self.get_page(page) embed = await self.get_embed(entries, page, first=first) if not self.message: self.message = await self.ctx.send("Loading...") if not self.paginating: return await self.message.edit(content=None, embed=embed) await self.message.edit(content=None, embed=embed) if not first: return for (reaction, _) in self.reaction_emojis: if self.maximum_pages == 2 and reaction in ('\u23ed', '\u23ee'): # no |<< or >>| buttons if we only have two pages # we can't forbid it if someone ends up using it but remove # it from the default set continue await self.message.add_reaction(reaction)
async def edit_trophyboard_format(self, ctx): """Edit the format of the guild's trophyboard. The bot will provide 2 options and you must select 1 via reactions. **Format** :information_source: `+edit trophyboard format` **Example** :white_check_mark: `+edit trophyboard format` **Required Permissions** :warning: Manage Server """ table = CLYTable() table.add_rows([[0, 4320, 955, 'Member Name'], [1, 4500, 870, 'Another Member'], [2, 3900, -600, 'Yet Another'], [3, 1500, -1000, 'Worst Pusher']]) table.title = '**Option 1 Example**' option_1_render = f'**Option 1 Example**\n{table.trophyboard_1()}' table.clear_rows() table.add_rows([[0, 2000, 'Member'], [1, 1500, 'Nearly #1'], [2, 1490, 'Another Member'], [3, -600, 'Winner']]) option_2_render = f'**Option 2 Example**\n{table.trophyboard_2()}' embed = discord.Embed(colour=self.bot.colour) fmt = f'{option_1_render}\n\n\n{option_2_render}\n\n\n' \ f'These are the 2 available default options.\n' \ f'Please hit the reaction of the format you \nwish to display on the trophyboard.' embed.description = fmt msg = await ctx.send(embed=embed) query = "UPDATE boards SET render=$1 WHERE channel_id=$2" reactions = [ '1\N{combining enclosing keycap}', '2\N{combining enclosing keycap}' ] for r in reactions: await msg.add_reaction(r) def check(r, u): return str( r ) in reactions and u.id == ctx.author.id and r.message.id == msg.id try: r, u = await self.bot.wait_for('reaction_add', check=check, timeout=60.0) except asyncio.TimeoutError: await ctx.db.execute(query, 1, ctx.config.channel_id) return await ctx.send('You took too long. Option 1 was chosen.') await ctx.db.execute(query, reactions.index(str(r)) + 1, ctx.config.channel_id) await ctx.confirm()