<commit_before>from discord.ext import commands
import aiohttp
from bs4 import BeautifulSoup

#WIP-This cog will not work correctly as is. 
class revimage:
    """Reverse image search commands"""
    def __init__(self, bot):
        self.bot = bot
        self.tineye_session = aiohttp.ClientSession()

    def __unload(self):
        self.tineye_session.close()

    def _tag_to_title(self, tag):
        return tag.replace(' ', ', ').replace('_', ' ').title()

    @commands.command(pass_context=True)
    async def tineye(self, ctx, link=None):
        """
        Reverse image search using tineye
        usage:  .tineye <image-link> or
                .tineye on image upload comment
        """
        file = ctx.message.attachments
        if link is None and not file:
            await self.bot.say('Message didn\'t contain Image')
        else:
            await self.bot.type()
            if file:
                url = file[0]['proxy_url']
            else:
                url = link
            async with self.tineye_session.get('https://tineye.com/search/?url={}'.format(url)) as response:
                soup = BeautifulSoup(await response.text(), 'html.parser')
                pages = []
                image_link = None
                try:
                    hidden = soup.find(class_='match').select('.hidden-xs')[0]
                    if hidden.contents[0].startswith('Page:'):
                        pages.append('<{}>'.format(hidden.next_sibling['href']))
                    else:
                        image_link = hidden.a['href']
                except AttributeError:
                    message = '\n**No matches found**'
#            message = '\n**Pages:** '
#            message += '\n**Pages:** '.join(pages)
            if image_link is not None:
                message = '\n**Image Found:** \n<{}>'.format(image_link)
            await self.bot.reply(message)


def setup(bot):<commit_msg>add search link<commit_after>from discord.ext import commands
import aiohttp
from bs4 import BeautifulSoup

#WIP-This cog will not work correctly as is. 
class revimage:
    """Reverse image search commands"""
    def __init__(self, bot):
        self.bot = bot
        self.tineye_session = aiohttp.ClientSession()

    def __unload(self):
        self.tineye_session.close()

    def _tag_to_title(self, tag):
        return tag.replace(' ', ', ').replace('_', ' ').title()

    @commands.command(pass_context=True)
    async def tineye(self, ctx, link=None):
        """
        Reverse image search using tineye
        usage:  .tineye <image-link> or
                .tineye on image upload comment
        """
        file = ctx.message.attachments
        if link is None and not file:
            await self.bot.say('Message didn\'t contain Image')
        else:
            await self.bot.type()
            if file:
                url = file[0]['proxy_url']
            else:
                url = link
            async with self.tineye_session.get('https://tineye.com/search/?url={}'.format(url)) as response:
                soup = BeautifulSoup(await response.text(), 'html.parser')
                pages = []
                image_link = None
                try:
                    hidden = soup.find(class_='match').select('.hidden-xs')[0]
                    if hidden.contents[0].startswith('Page:'):
                        pages.append('<{}>'.format(hidden.next_sibling['href']))
                    else:
                        image_link = hidden.a['href']
                except AttributeError:
                    message = '\n**No matches found**'
                    message += '**Full Search:**\nhttps://tineye.com/search/?url={}'.format(url)
#            message = '\n**Pages:** '
#            message += '\n**Pages:** '.join(pages)
            if image_link is not None:
                message = '\n**Image Found:** \n<{}>'.format(image_link)
                message += '\n**Full Search:**\nhttps://tineye.com/search/?url={}'.format(url)
            await self.bot.reply(message)


def setup(bot):
{'fraction_non_alphanumeric': 0.13397246804326451, 'fraction_numerical': 0.0019665683382497543, 'mean_word_length': 1.7793715846994536, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '471135', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1131, 'n_words': 267}