Exemplo n.º 1
0
 async def i(self, ctx, *, query):
     """Google image search. [p]i Lillie pokemon sun and moon"""
     await ctx.message.delete()
     config = load_optional_config()
     if query[0].isdigit():
         item = int(query[0])
         query = query[1:]
     else:
         item = 0
     async with aiohttp.ClientSession() as session:
         async with session.get("https://www.googleapis.com/customsearch/v1?q=" + urllib.parse.quote_plus(query) + "&start=" + '1' + "&key=" + config['google_api_key'] + "&cx=" + config['custom_search_engine'] + "&searchType=image") as resp:
             if resp.status != 200:
                 if not config['google_api_key'] or not config['custom_search_engine']:
                     return await ctx.send(self.bot.bot_prefix + "You don't seem to have image searching configured properly. Refer to the wiki for details.")
                 return await ctx.send(self.bot.bot_prefix + 'Google failed to respond.')
             else:
                 result = json.loads(await resp.text())
                 try:
                     result['items']
                 except:
                     return await ctx.send(self.bot.bot_prefix + 'There were no results to your search. Use more common search query or make sure you have image search enabled for your custom search engine.')
                 if len(result['items']) < 1:
                     return await ctx.send(self.bot.bot_prefix + 'There were no results to your search. Use more common search query or make sure you have image search enabled for your custom search engine.')
                 em = discord.Embed()
                 if embed_perms(ctx.message):
                     em.set_image(url=result['items'][item]['link'])
                     show_search = get_config_value("optional_config", "show_search_term")
                     if show_search == "True":
                         em.set_footer(text="Search term: \"" + query + "\"")
                     await ctx.send(content=None, embed=em)
                 else:
                     await ctx.send(result['items'][item]['link'])
                     await ctx.send("Search term: \"" + query + "\"")
Exemplo n.º 2
0
 async def i(self, ctx, *, query):
     """Google image search. [p]i Lillie pokemon sun and moon"""
     await ctx.message.delete()
     config = load_optional_config()
     if query[0].isdigit():
         item = int(query[0])
         query = query[1:]
     else:
         item = 0
     async with self.bot.session.get("https://www.googleapis.com/customsearch/v1?q=" + urllib.parse.quote_plus(query) + "&start=" + '1' + "&key=" + config['google_api_key'] + "&cx=" + config['custom_search_engine'] + "&searchType=image") as resp:
         if resp.status != 200:
             if not config['google_api_key'] or not config['custom_search_engine']:
                 return await ctx.send(self.bot.bot_prefix + "You don't seem to have image searching configured properly. Refer to the wiki for details.")
             return await ctx.send(self.bot.bot_prefix + 'Google failed to respond.')
         else:
             result = json.loads(await resp.text())
             try:
                 result['items']
             except:
                 return await ctx.send(self.bot.bot_prefix + 'There were no results to your search. Use more common search query or make sure you have image search enabled for your custom search engine.')
             if len(result['items']) < 1:
                 return await ctx.send(self.bot.bot_prefix + 'There were no results to your search. Use more common search query or make sure you have image search enabled for your custom search engine.')
             em = discord.Embed()
             if embed_perms(ctx.message):
                 em.set_image(url=result['items'][item]['link'])
                 show_search = get_config_value("optional_config", "show_search_term")
                 if show_search == "True":
                     em.set_footer(text="Search term: \"" + query + "\"")
                 await ctx.send(content=None, embed=em)
             else:
                 await ctx.send(result['items'][item]['link'])
                 await ctx.send("Search term: \"" + query + "\"")
Exemplo n.º 3
0
 async def shorten(self, ctx, url):
     try:
         ldata = { "token": get_config_value("optional_config", "cadence_pass"), "target": url }
         response = requests.post('https://cadence.moe/api/urls', data=json.dumps(ldata))
         lres = response.json()
         urlhash = str(lres["hash"])
         await ctx.send(f"<https://cadence.moe/api/urls/{urlhash}>")
     except requests.exceptions.HTTPError as error:
         await ctx.send("Something went wrong while generating the url. Aborting.")
         with open(error) as fp:
             output = fp.read()
             url = await hastebin(output, self.bot.session)
             await ctx.send('Error: ' + url)
Exemplo n.º 4
0
 async def ascii(self, ctx, *, msg):
     """Convert text to ascii art. Ex: [p]ascii stuff [p]help ascii for more info."""
     if ctx.invoked_subcommand is None:
         if msg:
             font = get_config_value("optional_config", "ascii_font")
             msg = str(figlet_format(msg.strip(), font=font))
             if len(msg) > 2000:
                 await ctx.send(self.bot.bot_prefix + 'Message too long, RIP.')
             else:
                 await ctx.message.delete()
                 await ctx.send(self.bot.bot_prefix + '```\n{}\n```'.format(msg))
         else:
             await ctx.send(
                            self.bot.bot_prefix + 'Please input text to convert to ascii art. Ex: ``>ascii stuff``')
Exemplo n.º 5
0
 async def ascii(self, ctx, *, msg):
     """Convert text to ascii art. Ex: [p]ascii stuff [p]help ascii for more info."""
     if ctx.invoked_subcommand is None:
         if msg:
             font = get_config_value("optional_config", "ascii_font")
             msg = str(figlet_format(msg.strip(), font=font))
             if len(msg) > 2000:
                 await ctx.send(self.bot.bot_prefix + 'Message too long, RIP.')
             else:
                 await ctx.message.delete()
                 await ctx.send(self.bot.bot_prefix + '```\n{}\n```'.format(msg))
         else:
             await ctx.send(
                            self.bot.bot_prefix + 'Please input text to convert to ascii art. Ex: ``>ascii stuff``')
Exemplo n.º 6
0
    async def quote(self, ctx, *, msg: str = ""):
        """Quote a message. [p]help quote for more info.
        [p]quote - quotes the last message sent in the channel.
        [p]quote <words> - tries to search for a message in the server that contains the given words and quotes it.
        [p]quote <message_id> - quotes the message with the given message ID. Ex: [p]quote 302355374524644290 (enable developer mode to copy message IDs)
        [p]quote <user_mention_name_or_id> - quotes the last message sent by a specific user
        [p]quote <words> | channel=<channel_name> - quotes the message with the given words in a specified channel
        [p]quote <message_id> | channel=<channel_name> - quotes the message with the given message ID in a specified channel
        [p]quote <user_mention_name_or_id> | channel=<channel_name> - quotes the last message sent by a specific user in a specified channel
        """
        
        ###await ctx.message.delete()
        result = None
        channels = [ctx.channel] + [x for x in ctx.guild.channels if x != ctx.channel and type(x) == discord.channel.TextChannel]
        
        args = msg.split(" | ")
        msg = args[0]
        if len(args) > 1:
            channel = args[1].split("channel=")[1]
            channels = []
            for chan in ctx.guild.channels:
                if chan.name == channel or str(chan.id) == channel:
                    channels.append(chan)
                    break
            else:
                for guild in self.bot.guilds:
                    for chan in guild.channels:
                        if chan.name == channel or str(chan.id) == channel and type(chan) == discord.channel.TextChannel:
                            channels.append(chan)
                            break
            if not channels:
                return await ctx.send(self.bot.bot_prefix + "The specified channel could not be found.")
            
        user = get_user(ctx.message, msg)

        async def get_quote(msg, channels, user):
            for channel in channels:
                try:
                    if user:
                        async for message in channel.history(limit=500):
                            if message.author == user:
                                return message
                    if len(msg) > 15 and msg.isdigit():
                        async for message in channel.history(limit=500):
                            if str(message.id) == msg:
                                return message
                    else:
                        async for message in channel.history(limit=500):
                            if msg in message.content:
                                return message
                except discord.Forbidden:
                    continue
            return None
            
        if msg:
            result = await get_quote(msg, channels, user)
        else:
            async for message in ctx.channel.history(limit=1):
                result = message
        
        if result:
            if type(result.author) == discord.User:
                sender = result.author.name
            else:
                sender = result.author.nick if result.author.nick else result.author.name
            if embed_perms(ctx.message) and result.content:
                color = get_config_value("optional_config", "quoteembed_color")
                if color == "auto":
                    color = result.author.top_role.color
                elif color == "":
                    color = 0xbc0b0b
                else:
                    color = int('0x' + color, 16)
                em = discord.Embed(color=color, description=result.content, timestamp=result.created_at)
                em.set_author(name=sender, icon_url=result.author.avatar_url)
                footer = ""
                if result.channel != ctx.channel:
                    footer += "#" + result.channel.name
                    
                if result.guild != ctx.guild:
                    footer += " | " + result.guild.name
                    
                if footer:
                    em.set_footer(text=footer)
                await ctx.send(embed=em)
            elif result.content:
                await ctx.send('%s - %s```%s```' % (sender, result.created_at, result.content))
            else:
                await ctx.send(self.bot.bot_prefix + "Embeds cannot be quoted.")
        else:
            await ctx.send(self.bot.bot_prefix + 'No quote found.')
Exemplo n.º 7
0
    async def noquote(self, ctx, *, msg: str = None):
        """Quote a message, anonymously. >help quote for more info.
        >noquote - quotes the last message sent in the channel.
        >noquote <words> - tries to search for a message in the server that contains the given words and quotes it.
        >noquote <message_id> - quotes the message with the given message id. Ex: >quote 302355374524644290(Enable developer mode to copy message ids).
        >noquote <words> | channel=<channel_name> - quotes the message with the given words from the channel name specified in the second argument
        >noquote <message_id> | channel=<channel_name> - quotes the message with the given message id in the given channel name
        >noquote <user_mention_name_or_id> - quotes the last member sent by a specific user"""

        await ctx.message.delete()
        result = None
        pre = cmd_prefix_len()
        channel = ctx.channel
        if msg:
            user = get_user(ctx.message, msg)
            if " | channel=" in msg:
                channel = next((ch for ch in self.bot.get_all_channels()
                                if ch.name == msg.split("| channel=")[1]),
                               None)
                msg = msg.split(" | channel=")[0]
                if not channel:
                    return await ctx.send(self.bot.bot_prefix +
                                          "Could not find specified channel.")
            if not isinstance(channel, discord.channel.TextChannel):
                return await ctx.send(
                    self.bot.bot_prefix +
                    "This command is only supported in server text channels.")
            if user:
                async for message in ctx.message.channel.history(limit=500):
                    if message.author == user:
                        result = message
                        break
            try:
                length = len(self.bot.all_log[str(ctx.message.channel.id) +
                                              ' ' + str(ctx.message.guild.id)])
            except:
                pass
            else:
                if not result:
                    size = length if length < 201 else 200
                    for channel in ctx.message.guild.channels:
                        if type(channel) == discord.channel.TextChannel:
                            if str(channel.id) + ' ' + str(
                                    ctx.message.guild.id) in self.bot.all_log:
                                for i in range(length - 2, length - size, -1):
                                    try:
                                        search = self.bot.all_log[
                                            str(channel.id) + ' ' +
                                            str(ctx.message.guild.id)][i]
                                    except:
                                        continue
                                    if (msg.lower().strip()
                                            in search[0].content.lower() and
                                        (search[0].author != ctx.message.author
                                         or search[0].content[pre:7] !=
                                         'quote ')) or (msg.strip() == str(
                                             search[0].id)):
                                        result = search[0]
                                        break
                                if result:
                                    break

            if not result:
                try:
                    async for sent_message in channel.history(limit=500):
                        if (msg.lower().strip() in sent_message.content and
                            (sent_message.author != ctx.message.author
                             or sent_message.content[pre:7] != 'quote ')) or (
                                 msg.strip() == str(sent_message.id)):
                            result = sent_message
                            break
                except:
                    pass
        else:
            if not isinstance(channel, discord.channel.TextChannel):
                return await ctx.send(
                    self.bot.bot_prefix +
                    "This command is only supported in server text channels.")
            try:
                search = self.bot.all_log[str(ctx.message.channel.id) + ' ' +
                                          str(ctx.message.guild.id)][-2]
                result = search[0]
            except KeyError:
                try:
                    messages = await channel.history(limit=2).flatten()
                    result = messages[0]
                except:
                    pass

        if result:
            if type(result.author) == discord.User:
                sender = result.author.name
            else:
                sender = result.author.nick if result.author.nick else result.author.name
            if embed_perms(ctx.message) and result.content:
                color = get_config_value("optional_config", "quoteembed_color")
                if color == "auto":
                    color = result.author.top_role.color
                elif color == "":
                    color = 0xbc0b0b
                else:
                    color = int('0x' + color, 16)
                em = discord.Embed(color=color,
                                   description=result.content,
                                   timestamp=result.created_at)
                em.set_author(name="Anonymous")
                await ctx.send(embed=em)
            elif result.content:
                await ctx.send('%s - %s```%s```' %
                               (sender, result.created_at, result.content))
            else:
                await ctx.send(self.bot.bot_prefix +
                               "Embeds cannot be quoted.")
        else:
            await ctx.send(self.bot.bot_prefix + 'No quote found.')
Exemplo n.º 8
0
    async def quote(self, ctx, *, msg: str = ""):
        """Quote a message. [p]help quote for more info.
        [p]quote - quotes the last message sent in the channel.
        [p]quote <words> - tries to search for a message in the server that contains the given words and quotes it.
        [p]quote <message_id> - quotes the message with the given message ID. Ex: [p]quote 302355374524644290 (enable developer mode to copy message IDs)
        [p]quote <user_mention_name_or_id> - quotes the last message sent by a specific user
        [p]quote <words> | channel=<channel_name> - quotes the message with the given words in a specified channel
        [p]quote <message_id> | channel=<channel_name> - quotes the message with the given message ID in a specified channel
        [p]quote <user_mention_name_or_id> | channel=<channel_name> - quotes the last message sent by a specific user in a specified channel
        """
        
        await ctx.message.delete()
        result = None
        channels = [ctx.channel] + [x for x in ctx.guild.channels if x != ctx.channel and type(x) == discord.channel.TextChannel]
        
        args = msg.split(" | ")
        msg = args[0]
        if len(args) > 1:
            channel = args[1].split("channel=")[1]
            channels = []
            for chan in ctx.guild.channels:
                if chan.name == channel or str(chan.id) == channel:
                    channels.append(chan)
                    break
            else:
                for guild in self.bot.guilds:
                    for chan in guild.channels:
                        if chan.name == channel or str(chan.id) == channel and type(chan) == discord.channel.TextChannel:
                            channels.append(chan)
                            break
            if not channels:
                return await ctx.send(self.bot.bot_prefix + "The specified channel could not be found.")
            
        user = get_user(ctx.message, msg)

        async def get_quote(msg, channels, user):
            for channel in channels:
                try:
                    if user:
                        async for message in channel.history(limit=500):
                            if message.author == user:
                                return message
                    if len(msg) > 15 and msg.isdigit():
                        async for message in channel.history(limit=500):
                            if str(message.id) == msg:
                                return message
                    else:
                        async for message in channel.history(limit=500):
                            if msg in message.content:
                                return message
                except discord.Forbidden:
                    continue
            return None
            
        if msg:
            result = await get_quote(msg, channels, user)
        else:
            async for message in ctx.channel.history(limit=1):
                result = message
        
        if result:
            if type(result.author) == discord.User:
                sender = result.author.name
            else:
                sender = result.author.nick if result.author.nick else result.author.name
            if embed_perms(ctx.message) and result.content:
                color = get_config_value("optional_config", "quoteembed_color")
                if color == "auto":
                    color = result.author.top_role.color
                elif color == "":
                    color = 0xbc0b0b
                else:
                    color = int('0x' + color, 16)
                em = discord.Embed(color=color, description=result.content, timestamp=result.created_at)
                em.set_author(name=sender, icon_url=result.author.avatar_url)
                footer = ""
                if result.channel != ctx.channel:
                    footer += "#" + result.channel.name
                    
                if result.guild != ctx.guild:
                    footer += " | " + result.guild.name
                    
                if footer:
                    em.set_footer(text=footer)
                await ctx.send(embed=em)
            elif result.content:
                await ctx.send('%s - %s```%s```' % (sender, result.created_at, result.content))
            else:
                await ctx.send(self.bot.bot_prefix + "Embeds cannot be quoted.")
        else:
            await ctx.send(self.bot.bot_prefix + 'No quote found.')