예제 #1
0
    async def wordnik_search(self, ctx, *args):
        """: !d <word>          | Lookup a word in the dictionary"""
        message = utils.parse_message(ctx.message.content)

        lookup = self.wordApi.getDefinitions(message)

        if lookup is None:
            await self.bot.send_message(ctx.message.channel,
                                        "No results found.")
            return

        else:
            # For now, only work with the first definition given. lookup[0]
            word = lookup[0].word
            pos = lookup[0].partOfSpeech
            definition = lookup[0].text
            examples = lookup[0].exampleUses

            embed = discord.Embed(name='\u2063', colour=0x006FFA)
            embed.set_author(name="Wordnik",
                             icon_url="https://www.wordnik.com/favicon.ico")
            embed.add_field(name=word, value=pos)
            embed.add_field(name='\u2063', value=definition)

            if examples:
                embed.add_field(name="Example", value=examples)

            await self.bot.send_message(ctx.message.channel, embed=embed)
예제 #2
0
파일: wiki.py 프로젝트: Shadoukun/Diana
    async def wiki_search(self, ctx, *args):
        """: !wiki <word>       | Lookup something up on Wikipedia."""

        message = utils.parse_message(ctx.message.content)

        try:
            article = wikipedia.page(message, auto_suggest=False)

            embed = discord.Embed(title="\u2063", colour=0xF9F9F9)
            embed.set_author(
                name="Wikipedia",
                icon_url=
                "https://www.wikipedia.org/static/favicon/wikipedia.ico")
            embed.add_field(name=article.title,
                            value=article.summary.split('\n', 1)[0],
                            inline=True)

            await self.bot.send_message(ctx.message.channel, embed=embed)

        except wikipedia.DisambiguationError as e:
            title = "'{t}' may refer to:\n".format(t=e.title)
            text = '\n'.join(e.options[:10])

            embed = discord.Embed(title="\u2063", colour=0xF9F9F9)
            embed.set_author(
                name="Wikipedia",
                icon_url=
                "https://www.wikipedia.org/static/favicon/wikipedia.ico")
            embed.add_field(name=title, value=text, inline=True)

            await self.bot.send_message(ctx.message.channel, embed=embed)

        except wikipedia.PageError as e:
            await self.bot.send_message(ctx.message.channel,
                                        "No results found.")
예제 #3
0
    async def imdb_search(self, ctx, *args):
        """: !imdb <title>      | lookup a movie on IMDB. """
        message = utils.parse_message(ctx.message.content)
        r = self.session.get(self.url + message)

        if r.status_code == 200:
            movie = json.loads(r.text)
        else:
            await self.bot.send_message(ctx.message.channel,
                                        "No Results Found.")

        if movie['Response'] == "True":
            embed = discord.Embed(title="\n", colour=0x006FFA)
            embed.set_image(url=movie['Poster'])
            embed.set_author(name="IMDB",
                             icon_url="http://www.imdb.com/favicon.ico")
            embed.add_field(name="Title", value=movie['Title'], inline=False)
            embed.add_field(name="IMDB rating",
                            value=movie['imdbRating'],
                            inline=False)
            embed.add_field(name="Year", value=movie['Year'], inline=False)
            embed.add_field(name="Genre", value=movie['Genre'], inline=False)
            embed.add_field(name="Director",
                            value=movie['Director'],
                            inline=False)
            embed.add_field(name="Actors", value=movie['Actors'])
            embed.add_field(name="Plot", value=movie['Plot'])
            await self.bot.send_message(ctx.message.channel, embed=embed)

        else:
            await self.bot.send_message(ctx.message.channel,
                                        "No Results Found.")
예제 #4
0
    async def urbandict_search(self, ctx, *args):
        """: !ud <word>         | lookup a word on UrbanDictionary."""

        message = utils.parse_message(ctx.message.content)

        # Returns first entry for requested word.

        try:
            r = self.session.get(self.url + message)
            response = json.loads(r.text)['list'][0]

        except:
            await self.bot.send_message(ctx.message.channel,
                                        "No Results Found.")
            return

        definition = response['definition']
        permalink = response['permalink']
        title = response['word']
        example = "_" + response['example'] + "_"

        embed = discord.Embed(title="\n", url=permalink, colour=0xE86222)
        embed.set_author(
            name="urbandictionary",
            icon_url="https://www.urbandictionary.com/favicon.ico")
        embed.add_field(name=title,
                        value=definition + "\n\n" + example,
                        inline=False)

        await self.bot.send_message(ctx.message.channel, embed=embed)
예제 #5
0
    async def gelbooru_search(self, ctx, *args):
        """: !cum <tags>        | Post a random image from Gelboorur"""

        channel = str(ctx.message.channel)

        if ctx.invoked_subcommand is None:
            message = utils.parse_message(ctx.message.content,
                                          tags=self.default_tags[channel])
            count = self.gelbooru_count(message)

            if count:
                pageid = self.getRandomPage(count)
            else:
                msg = "No Results Found."
                await self.bot.send_message(ctx.message.channel, msg)
                return

            # Search
            r = self.session.get(self.url + message + "&pid=" + str(pageid))
            soup = BeautifulSoup(r.content, "html.parser")
            posts = soup.find_all("post")
            post = await self.getRandomPost(posts, count)

            if post:
                embed = self.create_embed(post)
                await self.bot.send_message(ctx.message.channel, embed=embed)
            else:

                msg = "All images already seen, Try again later."
                await self.bot.send_message(ctx.message.channel, msg)
                return
예제 #6
0
    async def verbose_search():

        message = utils.parse_message(ctx.message.content)

        if message:
            res = self.client.query(message, stream=True)

            embed = discord.Embed(title="\n", colour=0xFF6600)
            embed.set_author(name="WolframAlpha", icon_url="https://www.wolframalpha.com/favicon.ico")
            #podlist = [x for x in res.pods]

            for pod in podlist[0:3]:
                embed.add_field(name=pod.title, value="`" + pod.text + "`", inline=False)


            await self.bot.send_message(ctx.message.channel, embed=embed)
예제 #7
0
    async def e621_search(self, ctx, *args):
        """: !fur <tags>        | Post random a image from e621"""

        channel = ctx.message.channel
        message = utils.parse_message(ctx.message.content,
                                      tags=self.default_tags)

        # Only respond in the furry channels.
        if "fur" not in str(channel):
            return

        r = requests.get(self.url + message)

        # If response is OK, continue.
        if r.status_code == 200:
            # parse page and get number of posts
            soup = BeautifulSoup(r.content, "xml")
            count = len(soup.find_all("post"))

            # Calculate number of pages (posts/limit), and search one at random.
            maxpage = int(round(count / 320))

            if maxpage < 1:
                maxpage = 1

            pid = list(range(0, maxpage))
            random.shuffle(pid)
            r = self.session.get(self.url + message + "&page=" + str(pid[0]))
            soup = BeautifulSoup(r.content, "lxml")
            posts = soup.find_all("post")

            if len(posts) is 0:
                msg = "No Results Found."
                await self.bot.send_message(ctx.message.channel, msg)
                return

            post = await self.getRandomPost(posts)

            if post:
                embed = self.create_embed(post)
                await self.bot.send_message(ctx.message.channel, embed=embed)

            else:
                msg = "All images have already been seen. Try again later."
                await self.bot.send_message(ctx.message.channel, msg)
예제 #8
0
    async def shotachan_search(self, ctx, *args):
        """: !shota <tags>      | Post a random image from the Shotachan Booru."""

        # if no tags, default
        message = utils.parse_message(ctx.message.content)

        # get number of pages
        maxpage = self.shotachan_count(message)

        # Choose random page number
        pid = list(range(0, int(maxpage)))
        random.shuffle(pid)

        # get posts
        url = self.post_url + message + "&page=" + str(pid[0])
        posts = json.loads(self.session.get(url).text)
        count = len(posts)

        # get random post
        if posts:
            post = await self.getRandomPost(posts)

        else:
            msg = "No Results Found."
            await self.bot.send_message(ctx.message.channel, msg)
            return

        # if random post returned, create embed.
        if post:
            embed = self.create_embed(post)
            await self.bot.send_message(ctx.message.channel, embed=embed)

        else:
            msg = "All images have already been seen. Try again later."
            await self.bot.send_message(ctx.message.channel, msg)
            return