async def urbandict(self, ctx, *, terms): embeds = [] try: async with self.http as http: data = await http.get(f"http://api.urbandictionary.com/v0/define", params={'term': terms}) await http.close() items = data['list'] for item in items: embed = discord.Embed(color=self.bot.colour) embed.title = item['word'] embed.set_author(name=item['author'], icon_url="https://images-ext-1.discordapp.net/external/Gp2DBilGEcbI2YR0qkOGVkivomBLwmkW_7v3K8cD1mg/https/cdn.discordapp.com/emojis/734991429843157042.png") embed.description = cyberformat.hyper_replace(str(item['definition']), old=['[', ']'], new=['', '']) embed.description += f"\n👍 **{item['thumbs_up']:,}** 👎 **{item['thumbs_down']}**" embed.add_field(name="Example", value=cyberformat.hyper_replace(str(item['example']), old=['[', ']'], new=['', ''])) embeds.append(embed) source = paginator.EmbedSource(embeds) menu = paginator.CatchAllMenu(source=source) menu.add_info_fields({"<:author:734991429843157042>": "The author of the post", ":thumbsup:": "How many thumbs up the post has", ":thumbsdown:": "How many thumbs down the post has"}) await menu.start(ctx) except (APIError, IndexError): raise commands.BadArgument(f"term not found on urban dictionary.")
async def horror(self, ctx, limit: int = 5): """spoopy""" posts = [] async with aiohttp.ClientSession() as cs: async with cs.get( f"https://www.reddit.com/r/twosentencehorror/hot.json" ) as r: res = await r.json() for i in res['data']['children']: posts.append(i['data']) counter = 0 embeds = [] async with ctx.typing(): for s in random.sample(posts, len(posts)): text = cyberformat.shorten( f"{s['title']}\n{s['selftext']}") embeds.append( discord.Embed(description=text[:2000], colour=self.bot.colour)) counter += 1 if counter == limit: break else: continue p = paginator.CatchAllMenu(paginator.EmbedSource(embeds)) await p.start(ctx)
async def reddit_pages(self, ctx, subreddit, limit: int = 5): """Gives you a paginated menu of any subreddit""" posts = [] u = '\u200b' async with self.bot.session.get(f"https://www.reddit.com/r/{subreddit}/hot.json", params={'limit': 100}) as r: res = await r.json() for i in res['data']['children']: if i['data']['over_18'] and not ctx.channel.is_nsfw(): raise commands.NSFWChannelRequired(ctx.channel) posts.append(i['data']) counter = 0 embeds = [] async with ctx.typing(): for s in random.sample(posts, len(posts)): embed = discord.Embed(title=str(s['title']), colour=self.bot.colour, url=f"https://reddit.com/{s['permalink']}") embed.set_author(name=s['author']) embed.set_footer(text=f"{s['upvote_ratio'] * 100:,}% upvote ratio | posted to r/{s['subreddit']}") if s['is_self']: embed.description = f"{s['selftext'].replace('**', f'{u}')}\n{self.up} **{s['score']:,}** :speech_balloon: **{s['num_comments']:,}** {self.share} **{s['num_crossposts']:,}** :medal: **{s['total_awards_received']}**" else: embed.set_image(url=s['url'].split("?")[0]) embed.description = f"{self.up} **{s['score']:,}** :speech_balloon: **{s['num_comments']:,}** {self.share} **{s['num_crossposts']:,}** :medal: **{s['total_awards_received']}**" embeds.append(embed) counter += 1 if counter == limit: break else: continue menu = paginator.CatchAllMenu(paginator.EmbedSource(embeds)) menu.add_info_fields({self.up: "How many upvotes the post has", "💬": "How many comments the post has", self.share: "How many shares/cross-posts the post has", ":medal:": "How many awards the post has"}) await menu.start(ctx)
async def snipe(self, ctx, **flags): """Shows the most recently deleted messages in a given channel""" # i know i shouldnt be using json for this channel = flags.get('channel') or ctx.channel with open('./json_files/snipes.json', 'r') as f: snipes = json.load(f) try: channel_snipes = snipes[str(channel.id)] except KeyError: return await ctx.send(f"{channel} has no deleted messages.") embeds = [] for snipe in reversed(channel_snipes[:flags.get('limit')]): author = self.bot.get_user(int( snipe['author'])) or await self.bot.fetch_user( int(snipe['author'])) embed = discord.Embed(colour=self.bot.colour) desc = snipe['content'] if not desc and snipe.get('embed'): desc = '`<Embedded Message>`' embed.description = desc since = dt.strptime(snipe['created_at'], '%Y-%m-%d %H:%M:%S.%f') embed.set_author(name=f"{author} said in {str(channel)}", icon_url=author.avatar_url) embed.timestamp = since embeds.append(embed) source = paginator.EmbedSource(embeds, footer=False) await paginator.CatchAllMenu(source).start(ctx)
async def emojis(self, ctx): """A paginated menu of all of the guild's emojis.""" embeds = [] for page in self.emote_pages(ctx, 20): embeds.append( discord.Embed(colour=self.bot.colour, description=page)) await paginator.CatchAllMenu(source=paginator.EmbedSource(embeds) ).start(ctx)
async def google(self, ctx, *, query=None): """Shows you google search results for a specified query""" client = async_cse.Search(self.bot.config.google_key) results = await client.search(query, safesearch=not (ctx.channel.is_nsfw())) embeds = [] for res in results: embeds.append( discord.Embed(colour=self.bot.colour, title=res.title, description=res.description, url=res.url)) source = paginator.EmbedSource(embeds) await client.close() await paginator.CatchAllMenu(source=source).start(ctx)
async def phelp(self, ctx, *, command=None): """ If you don't like the regular help command """ embeds = [] use = self.bot.get_command(command) if command else None lcogs = [str(cog) for cog in self.bot.cogs] if not command: for name, obj in self.bot.cogs.items(): embed = discord.Embed(title=f"{name} Commands", colour=self.bot.colour) cmds = [] for cmd in obj.get_commands(): cmds.append(f"→ `{cmd.name} {cmd.signature}` | {cmd.help}") embed.description = '\n'.join(cmds) if cmds: embeds.append(embed) else: continue pages = paginator.CatchAllMenu(paginator.EmbedSource([discord.Embed(colour=self.bot.colour, title=f'{self.bot.user.name} Help', description=f'Do `{ctx.prefix}help command/cog` for more info').set_image( url=self.bot.user.avatar_url)] + embeds)) await pages.start(ctx) elif command in lcogs: embed = discord.Embed(colour=self.bot.colour, title=f'{command.capitalize()} Help') embed.description = '\n'.join( [f"→ `{cmd.name} {cmd.signature}` | {cmd.help}" for cmd in self.bot.cogs[command].get_commands()]) await ctx.send(embed=embed) elif command and use: help_msg = use.help or "No help provided for this command" parent = use.full_parent_name if len(use.aliases) > 0: aliases = '|'.join(use.aliases) cmd_alias_format = f'{use.name}|{aliases}' if parent: cmd_alias_format = f'{parent} {cmd_alias_format}' alias = cmd_alias_format else: alias = use.name if not parent else f'{parent} {use.name}' embed = discord.Embed(title=f"{alias} {use.signature}", description=help_msg, colour=self.bot.colour) if isinstance(use, commands.Group): embed = discord.Embed(title=f"{alias} {use.signature}", description=help_msg, colour=self.bot.colour) for sub_cmd in use.commands: u = '\u200b' embed.add_field( name=f"{use.name} {sub_cmd.name}{'|' if sub_cmd.aliases else u}{'| '.join(sub_cmd.aliases)} {sub_cmd.signature}", value=f"{sub_cmd.help}", inline=False) await ctx.send(embed=embed) else: await ctx.send(embed=embed) elif command not in lcogs or command and not use: await ctx.send("not found")
async def wikipedia(self, ctx, *, search): embeds = [] async with ctx.typing(): wiki = aiowiki.Wiki.wikipedia() for page in (await wiki.opensearch(search)): embed = discord.Embed(colour=self.bot.colour) embed.title = page.title embed.url = (await page.urls())[0].split("(")[0] embed.description = (await page.summary())[:2000] + "..." embeds.append(embed) source = paginator.EmbedSource(embeds) await paginator.CatchAllMenu(source).start(ctx)
async def pfpcycle(self, ctx): """if you're reading this it probably isnt your business""" pfps = ['http://tinyurl.com/y8ccnxm3', 'https://images-ext-1.discordapp.net/external/6HjseNKji1C5wbK9Wb_jnIluzFWrCRW6xqhfboNtDDI/%3Fsize%3D1024/https/cdn.discordapp.com/avatars/350349365937700864/bbbff13a570231108b7afa383416b62a.png', 'http://tinyurl.com/ycjuvusq', 'https://cdn.discordapp.com/avatars/350349365937700864/f38bc11cf4360a9267a55962fcd71809.png?size=1024', 'https://media.discordapp.net/attachments/381963689470984203/732283634190516304/coolweavile.png?width=962&height=962', 'https://images-ext-1.discordapp.net/external/XVtT9nLyPYTWfNw4GSjvRMKibuKafi6_VCyVwSfW4C8/%3Fsize%3D1024/https/cdn.discordapp.com/avatars/350349365937700864/d027959b2a204f7587092a7a249e7377.png?width=962&height=962', 'https://media.discordapp.net/attachments/735325249138065468/735681377785348156/image0.png', 'https://media.discordapp.net/attachments/735325249138065468/735681378292596736/image1.png', 'https://media.discordapp.net/attachments/735325249138065468/735681378867478528/image2.png', 'https://media.discordapp.net/attachments/735325249138065468/735681379387441152/image3.png', 'https://media.discordapp.net/attachments/735325249138065468/735682125239681074/image0.png' 'http://i.some-random-api.ml/pokemon/weavile.png'] embeds = [discord.Embed(colour=self.bot.colour).set_image(url=p) for p in pfps] a = paginator.CatchAllMenu(paginator.EmbedSource(embeds)) await a.start(ctx)
async def giphy(self, ctx, *, query): """Get a random gif based on your query""" async with self.http as h: try: res = await h.get( 'http://api.giphy.com/v1/gifs/search?q=' + query + f'&api_key={self.bot.config.giphy}&limit=10') except Exception as error: raise commands.BadArgument(error) await h.close() data = res.get('data') embeds = [] for item in data: embed = discord.Embed(colour=self.bot.colour, title=f"> {item.get('title')}") embed.set_thumbnail(url='https://image.ibb.co/b0Gkwo/Poweredby_640px_Black_Vert_Text.png') embed.set_image(url=item.get('images')['original']['url']) embeds.append(embed) source = paginator.EmbedSource(embeds) menu = paginator.CatchAllMenu(source=source) await menu.start(ctx)
async def giphy(self, ctx, *, query): """Get a random gif based on your query""" URL = "http://api.giphy.com/v1/gifs/search?q={0}&api_key={1}&limit={2}" async with self.bot.session.get( URL.format(query, self.bot.config.giphy, 10)) as r: res = await r.json() data = res.get('data') embeds = [] for item in data: embed = discord.Embed(colour=self.bot.colour, title=f"> {item.get('title')}") embed.set_thumbnail( url= 'https://image.ibb.co/b0Gkwo/Poweredby_640px_Black_Vert_Text.png' ) embed.set_image(url=item.get('images')['original']['url']) embeds.append(embed) source = paginator.EmbedSource(embeds) menu = paginator.CatchAllMenu(source=source) await menu.start(ctx)
async def permissions(self, ctx, *, member: discord.Member = None): member = member or ctx.author perms = [] negperms = [] embed = discord.Embed(colour=self.bot.colour).set_author( name=f"{member}'s permissions in {ctx.channel}", icon_url=member.avatar_url) all = dict(member.permissions_in(ctx.channel)).items() for key, value in all: if value: perms.append( f"{ctx.tick()} **{str(key.title()).replace('_', ' ')}**") else: negperms.append( f"{ctx.tick(False)} **{str(key.title()).replace('_', ' ')}**" ) embed2 = discord.Embed(colour=self.bot.colour).set_author( name=embed.author.name, icon_url=member.avatar_url) embed.description = '\n'.join(perms) embed2.description = '\n'.join(negperms) source = paginator.EmbedSource([embed, embed2]) await paginator.CatchAllMenu(source=source).start(ctx)