async def snippet(self, ctx, *, name: str.lower = None): """ Create pre-defined messages for use in threads. When `{prefix}snippet` is used by itself, this will retrieve a list of snippets that are currently set. `{prefix}snippet-name` will show what the snippet point to. To create a snippet: - `{prefix}snippet add snippet-name A pre-defined text.` You can use your snippet in a thread channel with `{prefix}snippet-name`, the message "A pre-defined text." will be sent to the recipient. Currently, there is not a built-in anonymous snippet command; however, a workaround is available using `{prefix}alias`. Here is how: - `{prefix}alias add snippet-name anonreply A pre-defined anonymous text.` See also `{prefix}alias`. """ if name is not None: val = self.bot.snippets.get(name) if val is None: embed = create_not_found_embed( name, self.bot.snippets.keys(), "Snippet" ) return await ctx.send(embed=embed) return await ctx.send(escape_mentions(val)) if not self.bot.snippets: embed = discord.Embed( color=discord.Color.red(), description="You dont have any snippets at the moment.", ) embed.set_footer( text=f"Do {self.bot.prefix}help snippet for more commands." ) embed.set_author(name="Snippets", icon_url=ctx.guild.icon_url) 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) embed.set_author(name="Snippets", icon_url=ctx.guild.icon_url) embeds.append(embed) session = EmbedPaginatorSession(ctx, *embeds) await session.run()
async def meow_breeds(self, ctx): """ Fetch cat breeds! """ if self.meowkey is None: return await ctx.channel.send("No API key found!") async with self.bot.session.get("https://api.thecatapi.com/v1/breeds", headers={'x-api-key': self.meowkey}) as r: data = await r.json() breeds = [] for breed in data: # Bug with API for Javanese breed if breed.get("alt_names", " ").strip(): for alt_name in breed["alt_names"].split(','): breeds.append( f"{alt_name.strip().title()} (`{breed['id']}`)") breeds.append( f"{breed['name'].strip().title()} (`{breed['id']}`)") embeds = [] for i, names in enumerate(zip_longest(*(iter(sorted(breeds)), ) * 12)): description = utils.format_description(i, names) embed = discord.Embed(title=":cat: ~meow~", description=description) embeds.append(embed) async with self.bot.session.get( f"https://api.thecatapi.com/v1/images/search?limit={len(embeds)}", headers={'x-api-key': self.meowkey}) as r: data = await r.json() for cat, embed in zip(data, embeds): embed.set_image(url=cat["url"]) if cat.get("breeds"): embed.set_footer(text=", ".join(b["name"] for b in cat["breeds"])) session = EmbedPaginatorSession(ctx, *embeds) await session.run()
async def woof_breeds(self, ctx): """ Fetch a list of dog breeds. """ async with self.bot.session.get( "https://dog.ceo/api/breeds/list/all") as r: data = await r.json() if data["status"] == "error": return await ctx.channel.send(data["message"]) dogs = data["message"] breeds = [] for breed, sub_breeds in dogs.items(): breeds.append(breed.title()) for sub_breed in sub_breeds: breeds.append((sub_breed + " " + breed).title()) embeds = [] for i, names in enumerate(zip_longest(*(iter(sorted(breeds)), ) * 12)): description = utils.format_description(i, names) embed = discord.Embed(title=":dog: ~woof~", description=description) embeds.append(embed) async with self.bot.session.get( f"https://dog.ceo/api/breeds/image/random/{len(embeds)}") as r: data = await r.json() if data["status"] != "error": for dog, embed in zip(data["message"], embeds): embed.set_image(url=dog) breed, *sub_breed = dog.split('/')[-2].split('-') if sub_breed: breed = sub_breed[0] + " " + breed embed.set_footer(text=breed.title()) session = EmbedPaginatorSession(ctx, *embeds) await session.run()