async def show_leaderboard(self, ctx): ordered = await get_leaderboard(self.bot, ctx.guild) stringed = [ f"#{m['index']}. __**{m['name']}**__:\n" f"Level {m['d']['lvl']} | " f"XP {m['d']['xp']}\n\n" for m in ordered ] size = 5 grouped = [stringed[i:i + size] for i in range(0, len(stringed), size)] embeds = [] for group in grouped: string = "" embed = discord.Embed(title="Leaderboard", color=bot_config.COLOR) embed.set_thumbnail( url="https://i.ibb.co/CQvbvDq/trophy-1f3c6.png") for m in group: string += m embed.description = string embed.set_footer(icon_url=ctx.guild.icon_url, text=ctx.guild.name) embeds.append(embed) if len(embeds) == 0: await ctx.send("There isn't anyone on the leaderboard yet.") return paginator = disputils.BotEmbedPaginator(ctx, embeds) await paginator.run()
async def search_general(self, ctx, sql, arg): """ executes given sql with 1 given arg creates pages for resulting quote ids """ cur = self.conn.cursor() try: cur.execute(sql, (arg, )) except sqlite3.OperationalError: cur.close() return await ctx.send(":thinking: Nothing found.") quotes = [] for entry in cur.fetchall(): quote_id = entry[0] info = self.load_msg(quote_id) embeds = self.load_embeds(info["msg_id"]) attachments = await self.load_attachments(info["msg_id"]) quotes.append(self.make_embed(info, embeds, attachments)) cur.close() if not quotes: return await ctx.send(":thinking: Nothing found.") pag = disputils.BotEmbedPaginator(ctx, quotes) await pag.run()
async def discriminator(self, ctx, discrim=None): if discrim is None: return await ctx.send("Please provid a discriminator to search!") searching = await ctx.send("Searching... Please wait") result = "" count = 0 pages = [] async for member in ctx.guild.fetch_members(limit=None): if count == 10: pages.append( discord.Embed(title="Here are the results :", description=f"```js\n{result}\n```", color=0x406da2)) count = 0 result = "" if discrim == member.discriminator: count += 1 result += f"{member.id} {member}\n" continue if result == "" and len(pages) == 0: return await searching.edit(content="No member found...") if result != "": pages.append( discord.Embed(title="Here are the results :", description=f"```js\n{result}\n```", color=0x406da2)) await searching.delete() paginator = disputils.BotEmbedPaginator(ctx, pages) await paginator.run()
async def search(self, ctx, *, text=None): if text is None: return await ctx.send("Please provid something to search!") searching = await ctx.send("Searching... Please wait") result = "" found = 0 count = 0 pages = [] async for member in ctx.guild.fetch_members(limit=None): if count == 10: pages.append( discord.Embed(title="Here are the results :", description=f"```js\n{result}\n```", color=0x406da2)) count = 0 result = "" if text.lower() in member.name.lower(): count += 1 if member.nick is not None: result += f"{member.id} {member} ({member.nick})\n" continue result += f"{member.id} {member}\n" continue if member.nick is not None: if text.lower() in member.nick.lower(): count += 1 result += f"{member.id} {member} ({member.nick})\n" if result == "" and len(pages) == 0: return await searching.edit(content="No member found...") if result != "": pages.append( discord.Embed(title="Here are the results :", description=f"```js\n{result}\n```", color=0x406da2)) await searching.delete() paginator = disputils.BotEmbedPaginator(ctx, pages) await paginator.run()
async def ety(self, ctx, word, *flags): """Look up the etymology of a word. Add -soft to the end to look up words that are parts of other words. -r does something too I don't remember though""" is_soft = '-soft' in flags resources_ = flags[flags.index('-r') + 1:] if '-r' in flags else RESOURCES resources = [res.replace(',', '').strip() for res in resources_] def format_embed(fields, resource): embed = discord.Embed.from_dict({ 'color': 0xDD0000, 'title': word, 'author': { 'name': props[resource]['name'], 'icon_url': str(ctx.author.avatar_url) }, 'url': props[resource]['list']['url'].format(word), 'fields': fields }) return embed async with ctx.typing(): embeds = [ format_embed([{ 'value': ety.tree(word).__str__(), 'name': word }], 'wiki') ] for resource in resources: for fields in await self.scrape_fields(word, resource, is_soft): embeds.append(format_embed(fields, resource)) # from pprint import pprint # pprint([embed.to_dict() for embed in embeds]) paginator = disputils.BotEmbedPaginator(ctx, embeds) ctx.bot.loop.create_task(paginator.run())
async def _send_results(self, ctx, cells, word, mixed=False): reduced = [{cell.row: cell for cell in cells[0] if cell.row != 1}] if mixed: reduced += [{cell.row: cell for cell in cells[1] if cell.row != 3}] reduced += [{cell.row: cell for cell in cells[2]}] embeds = [] try: async with ctx.typing(): async with async_timeout.timeout(300): for chunk_idx, chunk in enumerate(reduced): for i, cell in enumerate(chunk.values()): embeds.append(await self._format_row( ctx, cell, word, chunk_idx, mixed)) if i == (0 if len(chunk) == 1 else 1): paginator = disputils.BotEmbedPaginator( ctx, embeds) ctx.bot.loop.create_task(paginator.run()) # print([embed.to_dict() for embed in embeds]) except asyncio.TimeoutError: pass if not embeds: await ctx.send("Query not found!")