async def get_waifu_by_id(self, mal_id):
     session = http_session.get_connection()
     async with session.get(API_URL + "character/{}".format(mal_id)) as resp:
         response = await resp.json()
     error = response.get('error', None)
     if error is not None:
         return None
     return response
    async def find_mal(self, kind, name, limit):
        response = ""
        params = {'q': name, 'limit': limit}
        session = http_session.get_connection()
        async with session.get(API_URL + f"search/{kind}/", params=params) as resp:
            response = await resp.json()

        error = response.get('error', None)
        if error is not None:
            return None
        return response
 async def insult(self, ctx: Context, member: discord.Member):
     name = member.nick if member.nick is not None else member.name
     author = ctx.message.author
     if member.id == self.bot.user.id:
         await ctx.send("No u.")
         name = author.nick if author.nick is not None else author.name
     session = http_session.get_connection()
     params = {'who': name}
     async with session.get("https://insult.mattbas.org/api/insult",
                            params=params) as resp:
         response = await resp.text()
     await ctx.send(response)
Example #4
0
 async def get_comic_char_by_id(self, comicvine_id):
     session = http_session.get_connection()
     params = {
         'api_key': COMICVINE_API_KEY,
         'format': 'json',
         'filter': f'id:{comicvine_id}',
         'field_list': 'name,real_name,image'
     }
     async with session.get(COMICVINE_URL + "characters",
                            params=params) as resp:
         response = await resp.json()
     if response['error'] != "OK":
         return None
     return response
 async def compliment(self, ctx: Context, member: discord.Member):
     if ctx.message.author.id == member.id:
         await ctx.send(
             "Complimenting yourself? That's sad. But hey, at least I like you.")
         return
     session = http_session.get_connection()
     async with session.get("https://complimentr.com/api") as resp:
         response = await resp.json()
     compliment = response["compliment"].capitalize() + "."
     await ctx.send("{}\n{}".format(member.mention, compliment))
     if member.id == self.bot.user.id:
         if ctx.message.author.id == self.newt_id:
             await ctx.send("*blushes*\nThanks Newt! ❤\n I-I-I love you too.❤")
         else:
             await ctx.send("Thanks I guess. {}!".format(ctx.message.author.mention))
 async def get_random_comic_char(self):
     global COMICVINE_TOTAL_CHARS
     session = http_session.get_connection()
     params = {
         'api_key': COMICVINE_API_KEY,
         'format': 'json',
         'limit': 1,
         'offset': random.randint(0, COMICVINE_TOTAL_CHARS)
     }
     async with session.get(COMICVINE_URL + "characters", params=params) as resp:
         response = await resp.json()
     if response['error'] != "OK":
         return None
     COMICVINE_TOTAL_CHARS = int(response['number_of_total_results'])
     return response
 async def find_comicvine_char(self, name):
     session = http_session.get_connection()
     params = {
         'api_key': COMICVINE_API_KEY,
         'format': 'json',
         'limit': 5,
         'query': name,
         'resources': 'character',
         'field_list': 'name,api_detail_url,real_name'
     }
     async with session.get(COMICVINE_URL + "search", params=params) as resp:
         response = await resp.json()
     if response['error'] != "OK":
         return None
     return response
    async def get_series_characters_by_id(self, kind, mal_id):
        session = http_session.get_connection()
        if kind == "anime":
            async with session.get(API_URL + f"{kind}/{mal_id}/characters_staff") as resp:
                response = await resp.json()
            async with session.get(API_URL + "{}/{}".format(kind, mal_id)) as resp:
                anime = await resp.json()
            response['title'] = anime.get('title', "") + " (A)"
        else:
            async with session.get(API_URL + "{}/{}/characters".format(kind, mal_id)) as resp:
                response = await resp.json()
            async with session.get(API_URL + "{}/{}".format(kind, mal_id)) as resp:
                manga = await resp.json()
            response['title'] = manga.get('title', "") + " (M)"

        error = response.get('error', None)
        if error is not None:
            return None
        return response
 async def schedule(self, ctx: Context, day: str):
     day = day.lower()
     session = http_session.get_connection()
     async with session.get(API_URL + "schedule/{}".format(day)) as resp:
         response = await resp.json()
     embed = discord.Embed(title=day.capitalize(), color=0x09D3E3)
     for anime in response[day]:
         desc = ""
         episodes = "N/A" if anime.get('episodes', None) is None else str(anime['episodes'])
         desc += "**Episodes**: " + episodes
         desc += "\n"
         desc += "**Genres:** "
         for genre in anime['genres']:
             desc += "*{}* ".format(genre['name'])
         desc += "\n"
         desc += "Score: " + str(anime['score'])
         desc += "\n"
         desc += "Source: " + anime['source']
         embed.add_field(name="**" + anime['title'] + "**", value=desc, inline=False)
     await ctx.send(embed=embed)
Example #10
0
    async def info(self, ctx: Context, *args: str):
        args = list(args)
        is_extended = False
        if args[-1].startswith('-extended'):
            DESCRIPTION_LIMIT = 1997
            SERIES_LIMIT = 20
            footer = "Use ?info to view shorter description."
            is_extended = True
            del args[-1]
        else:
            DESCRIPTION_LIMIT = 249
            SERIES_LIMIT = 2
            footer = "Use ?info name -extended to view extended description."
        if args[0].isdigit():
            response = await self.get_waifu_by_id(args[0])
            if response is None:
                await ctx.send("No character with that id found")
                return
        else:
            name = ' '.join(args)
            character_id = None
            response = await self.find_mal("character", name, 1)
            if response is None:
                await ctx.send("Character not found")
                return
            character = response['results'][0]
            character_id = str(character['mal_id'])
            response = ""
            session = http_session.get_connection()
            async with session.get(API_URL +
                                   f"/character/{character_id}/") as resp:
                response = await resp.json()

        description = response['about'][:DESCRIPTION_LIMIT]
        if len(response['about']) > DESCRIPTION_LIMIT:
            description += '...'
        title = f"{response['name']} ({response['name_kanji']}) ({response['mal_id']})"
        embed = discord.Embed(title=title,
                              description=description,
                              color=0x8700B6)
        if response.get('animeography', None) is not None and\
                response['animeography'] != []:
            anime_list = ""
            counter = 0
            for anime in response['animeography']:
                if counter == SERIES_LIMIT:
                    anime_list += "..."
                    break
                anime_list += anime['name']
                anime_list += "\n"
                counter += 1
            embed.add_field(name="Anime", value=anime_list, inline=False)
        if response.get('mangaography', None) is not None and\
                response['mangaography'] != []:
            manga_list = ""
            counter = 0
            for manga in response['mangaography']:
                if counter == SERIES_LIMIT:
                    manga_list += "..."
                    break
                manga_list += manga['name']
                manga_list += "\n"
                counter += 1
            embed.add_field(name="Manga", value=manga_list, inline=False)
        if is_extended:
            embed.add_field(name="Favorites",
                            value=response['member_favorites'])
        embed._image = {'url': str(response['image_url'])}
        embed.set_footer(text=footer)
        await ctx.send(embed=embed)
Example #11
0
 async def get_mal_waifu_pics(self, mal_id):
     session = http_session.get_connection()
     async with session.get(API_URL +
                            f"character/{mal_id}/pictures") as resp:
         pictures = await resp.json()
     return pictures
Example #12
0
    async def cinfo(self, ctx: Context, *args: str):
        args = list(args)
        author = ctx.message.author
        r_map = {
            0: "0⃣",
            1: "1⃣",
            2: "2⃣",
            3: "3⃣",
            4: "4⃣",
            5: "5⃣",
            "cancel": "⏹"
        }

        name = ' '.join(args)
        response = await self.find_comicvine_char(name)

        embed = discord.Embed(title=name.capitalize(), color=0x09d3e3)
        for i, character in enumerate(response['results']):
            embed.add_field(name=f"{i+1}: **{character['name']}**",
                            value=f"Real name: {character['real_name']}",
                            inline=False)
        msg = await ctx.send(embed=embed)

        for i in range(len(response['results'])):
            await msg.add_reaction(r_map[i + 1])
        await msg.add_reaction("⏹")

        def check(reaction, user):
            e = str(reaction.emoji)
            return e.startswith(('1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '⏹')) and user.id == author.id\
                and reaction.message.id == msg.id

        try:
            reaction, user = await self.bot.wait_for('reaction_add',
                                                     check=check,
                                                     timeout=60)
        except asyncio.TimeoutError:
            await msg.delete()
            await ctx.send("You didn't pick in time, too bad.")
            return
        await msg.delete()
        choice = None
        for k, v in r_map.items():
            if v == str(reaction.emoji):
                choice = k
                break

        if choice == "cancel":
            return

        url = response['results'][choice - 1]['api_detail_url']
        session = http_session.get_connection()
        params = {
            'api_key': COMICVINE_API_KEY,
            'format': 'json',
            'field_list': 'name,real_name,deck,image,site_detail_url'
        }
        async with session.get(url, params=params) as resp:
            response = await resp.json()

        character = response["results"]
        embed = discord.Embed(title=f"{character['name']}",
                              color=0x09d3e3,
                              url=character['site_detail_url'])
        embed._image = {'url': character['image']['medium_url']}
        embed.add_field(name="Real name",
                        value=character['real_name'],
                        inline=False)
        embed.add_field(name="Description",
                        value=character['deck'],
                        inline=False)
        await ctx.send(embed=embed)