Exemple #1
0
async def mal_character(event):
    """Search anime characters from Kantek itself
       Powered by jikan.moe

    Examples:
        {cmd} command
    """
    async with AioJikan() as jikan:
        sr = await jikan.search('character', event.text.split(" ", 1))
        c = await jikan.character(sr['results'][0]['mal_id'])
    if not c:
        await event.reply('err \\\nNo results found')
        return
    text = f'<b>{html.escape(c["name"])}'
    if c['name_kanji']:
        text += f' ({html.escape(c["name_kanji"])})'
    text += '</b>\n'
    about = html.escape(c['about'].replace('\\n', ''))
    text += f'<i>{about}</i>\n'
    pic = f'{c["image_url"]}'
    url = f'<a href="{html.escape(c["url"])}">read more</a>'
    text = text.strip()
    if len(text) > 1024:
        text = text[0:500] + ".... "
    text = text + url
    try:
        await event.reply(text,
                          file=pic,
                          link_preview=False,
                          parse_mode='html')
    except BaseException:
        await event.reply(text, link_preview=False, parse_mode='html')
Exemple #2
0
async def search(ctx, search: str):
    async with AioJikan() as aio_jikan:
        userResult = await aio_jikan.search(search_type='anime', query=search)
        userResult = userResult['results'][0]
    userEmbed = discord.Embed(title=userResult['title'], url=userResult['url'], description=userResult['synopsis'])
    userEmbed.set_thumbnail(url=userResult['image_url'])
    await ctx.send("Here you go!", embed=userEmbed)
Exemple #3
0
    async def manga(self, ctx, *, query):
        jikan = AioJikan()

        try:
            result = await jikan.search("manga", query)
        except APIException:
            await ctx.send("Problem connecting to the API. Please try again.")
            await jikan.close()
            return

        #taking first result for now
        if len(result["results"]) > 0:
            result = result["results"][0]
        else:
            await ctx.send(f"No results for <{query}>.")
            await jikan.close()
            return

        try:
            manga = await jikan.manga(result.get("mal_id"))
        except APIException:
            await ctx.send("Problem connecting to the API. Please try again.")
            await jikan.close()
            return

        title = manga.get("title")
        title_japanese = manga.get("title_japanese")
        url = manga.get("url")
        image = manga.get("image_url")
        synopsis = manga.get("synopsis")
        published = manga["published"].get("string")
        score = manga.get("score")
        broadcast = "N/A"
        if (chapters := manga.get("chapters")) is None:
            chapters = "N/A"
Exemple #4
0
async def mal_manga(e):
    await e.edit('Searching...')
    await e.delete()
    async with AioJikan() as jikan:
        sr = await jikan.search('manga', e.pattern_match.group(1))
        m = await jikan.manga(sr['results'][0]['mal_id'])
    if not m:
        await e.reply('err \\\nNo results found')
        return
    text = f'<b>{html.escape(m["title"])}'
    if m['title_japanese']:
        text += f' ({html.escape(m["title_japanese"])})'
    text += '</b>\n'
    text += f'<b>Score:</b> {m["score"]}\n'
    text += f'<b>Type:</b> {html.escape(m["type"])}\n'
    text += f'<b>Genres:</b> {", ".join([html.escape(i["name"]) for i in m["genres"]])}\n'
    text += f'<b>Status:</b> {html.escape(m["status"])}\n'
    if m['volumes']:
        text += f'<b>Volumes:</b> {m["volumes"]}\n'
    if m['chapters']:
        text += f'<b>Chapters:</b> {m["chapters"]}\n'
    text += f'<i>{html.escape(m["synopsis"])}</i>\n'
    pic = f'{m["image_url"]}'
    url = f'<a href="{html.escape(m["url"])}">read more</a>'
    text = text.strip()
    if len(text) > 1024:
        text = text[0:500] + ".... "
    text = text + url
    await e.reply(text, file=pic, link_preview=False, parse_mode='html')
async def main(loop):
    aio_jikan = AioJikan(loop=loop)

    mushishi = await aio_jikan.anime(457)
    # Close the connection to Jikan API
    # print(mushishi)
    # usernames = ['juanjg', 'thundersly', 'terabyte900']
    # jj = await aio_jikan.user(username='******', request='animelist')
    # jj = await aio_jikan.user(username='******')
    # top_anime = await aio_jikan.top(type='anime')
    # try:

    mushishi = await aio_jikan.anime(15000)
    # except:
    #     mushishi = await aio_jikan.anime(1)

    animes_data = []
    # for i in range (5):
    #     animes_data[i]= await aio_jikan.anime(i)

    # jj.keys()
    # print(mushishi)
    print(mushishi.keys())
    # print(mushishi['source'])
    # print(mushishi['related']['Adaptation'])

    # print(mushishi['studios'])

    await aio_jikan.close()
Exemple #6
0
async def main():
    async with AioJikan() as aio_jikan:
        mushishi = await aio_jikan.anime(457)
        pprint(mushishi)

        fma = await aio_jikan.manga(25)
        pprint(fma)

        ginko = await aio_jikan.character(425)
        pprint(ginko)

        naruto = await aio_jikan.search(search_type="anime", query="naruto")
        pprint(naruto)

        winter_2018 = await aio_jikan.season(year=2018, season="winter")
        pprint(winter_2018)

        monday = await aio_jikan.schedule(day="monday")
        pprint(monday)

        top_anime = await aio_jikan.top(type="anime")
        pprint(top_anime)

        meta = await aio_jikan.meta(request="requests",
                                    type="anime",
                                    period="today")
        pprint(meta)
Exemple #7
0
    async def anime(self, ctx, *, query: str):
        _jikan = AioJikan()
        while len(query) < 3:
            query += ' '

        async with ctx.typing():
            try:
                search = await _jikan.search(search_type='anime', query=query)
                anime = await _jikan.anime(id=search['results'][0]['mal_id'])

                title = anime[
                    'title_english'] + f" ({anime['title_japanese']})" if anime[
                        'title_japanese'] and anime[
                            'title_english'] else anime['title']
                desc = anime['synopsis'] if anime['synopsis'] and len(
                    anime['synopsis']
                ) < 1024 else anime['synopsis'][0:1021] + '...'
                rank = '#' + str(anime['rank'])
                popularity = '#' + str(anime['popularity'])
                genres = ', '.join(
                    [genre['name'] for genre in anime['genres']])

                anime_embed = Embed(color=0x00f00,
                                    title=title,
                                    url=anime['url'])
                anime_embed.set_thumbnail(url=anime['image_url'])
                anime_embed.add_field(name='Synopsis',
                                      value=desc,
                                      inline=False)
                anime_embed.add_field(name='Episode', value=anime['episodes'])
                anime_embed.add_field(name='Score', value=anime['score'])
                anime_embed.add_field(name='Ranking', value=rank)
                anime_embed.add_field(name='Popularity', value=popularity)
                anime_embed.add_field(name='Rating', value=anime['rating'])
                anime_embed.add_field(name='Aired',
                                      value=anime['aired']['string'])
                anime_embed.add_field(name='Genre', value=genres, inline=False)

                if anime['opening_themes']:
                    op_list = split_eps([op for op in anime['opening_themes']])
                    op_inline = '\n'.join(op_list)
                    anime_embed.add_field(name='Opening',
                                          value=op_inline[0:1024],
                                          inline=False)

                if anime['ending_themes']:
                    ed_list = split_eps([ed for ed in anime['ending_themes']])
                    ed_inline = '\n'.join(ed_list)
                    anime_embed.add_field(name='Ending',
                                          value=ed_inline[0:1024],
                                          inline=False)

                result = await ctx.send(embed=anime_embed)
            except APIException:
                result = await ctx.send(embed=wibu_404('Anime'))
            finally:
                await result.add_reaction('❗')
                await _jikan.close()
Exemple #8
0
async def anime_list(session, username):
    global jikan
    if jikan is None:
        jikan = AioJikan(session=session)
    d = await jikan.user(username, "animelist", "completed")
    return [
        Anime(x["title"], int(x["start_date"].split("-")[0]))
        for x in d["anime"]
    ]
Exemple #9
0
    def __init__(self,
                 config: ConfigBox,
                 *,
                 context: commands.Context = SubContext,
                 **kwargs):
        """
        :param config: Config parser object
        :param context: Context factory to use
        """
        super().__init__(
            command_prefix=kwargs.pop("command_prefix",
                                      self.get_command_prefix),
            case_insensitive=kwargs.pop("case_insensitive", True),
            max_messages=kwargs.pop("max_messages", 10_000),
            help_command=kwargs.pop("help_command", Minimal()),
            allowed_mentions=kwargs.pop(
                "allowed_mentions",
                discord.AllowedMentions(everyone=False,
                                        roles=False,
                                        users=False),
            ),
            activity=discord.Activity(
                type=discord.ActivityType.listening,
                name=f"{config.general.prefix}help",
            ),
            **kwargs,
        )
        self.config = config
        self.context = context
        self.jikan = AioJikan()
        self.ready_once = False
        self.uptime = datetime.now()
        # Todo: make an anime entry object to replace the dicts in the lists
        self.anime_db: Dict[str, list] = {}
        # {user_id: reason}
        self.blacklist: Dict[int, Optional[str]] = {}
        # {bot_id: {prefixes}}
        self.other_bot_prefixes: Dict[int,
                                      Set[str]] = defaultdict(lambda: set())
        # {guild_id: {prefixes}}
        self.prefixes: Dict[int, Set[str]] = defaultdict(
            lambda: {config.general.prefix})
        # {send_from: {send_to}}
        self.channel_links: Dict[discord.TextChannel,
                                 Set[discord.TextChannel]] = defaultdict(
                                     lambda: set())
        # {guild_id: {channel_id: deque[Snipe]}}
        self.snipes: Dict[int, Dict[int, Deque[Snipe]]] = defaultdict(
            lambda: defaultdict(lambda: deque(maxlen=5_000)))

        if config.extra_tokens.emote_collector:
            self.ec = EcClient(token=config.extra_tokens.emote_collector)

        else:
            self.ec = None

        self.add_check(self.blacklist_check)
Exemple #10
0
 def __init__(self, bot):
     self.bot = bot
     self.logger = logging.getLogger("TempleBot.weeb")
     self.british_timezone = pytz.timezone('Europe/London')
     self.logger.info("Opening MAL API event loop.")
     self.jikan_aio = AioJikan()
     self.cog_config = self.bot.get_cog_config("anime_manga_search_config")
     self.message_reaction_waiting_h_table = {}
     self.current_mal_req_count_ps = 0
     self.current_mal_req_count_pm = 0
Exemple #11
0
 async def weeb_search_command(self, ctx):
     ctx.message.content = ctx.message.content.strip(self.bot.command_prefix).strip("weeb_search ")
     try:
         await self.anime_title_request_func(ctx.message, ctx.message)
     except jikanpy.exceptions.APIException:
         self.logger.exception("jikanpy.exceptions.APIException raised, attempting API "
                               "restart.")
         await self.jikan_aio.close()
         self.jikan_aio = AioJikan()
         await self.anime_title_request_func(ctx.message, ctx.message)
     asyncio.create_task(self.mal_rate_limit_down_counter())
Exemple #12
0
async def test_containing_db(loop):
    async def write_data_to_db(record, recid, tags, db=None):

        await db.insert_to_table('records', record)
        for tag in tags:
            try:
                await db.insert_to_table('tags', {'tagname': tag},
                                         ignore_conflict=[
                                             'tagname',
                                         ])
            except UniqueViolationError:
                pass
            try:
                await db.insert_to_table('records_tags', {
                    'tagname': tag,
                    'recordid': recid
                })
            except UniqueViolationError:
                pass

    aio_jikan = AioJikan(loop=loop)

    cfg = Config()
    pg_pool = await asyncpg.create_pool(cfg.DB_ADDRESS)
    db = DbHandler(pg_pool=pg_pool, cfg=cfg)

    year_2000 = 2000
    seasons = ['winter', 'spring', 'summer', 'fall']

    for year in range(2015, 2019):
        for season in seasons:

            print(f'[+] reading {season} in {year}')

            season_year = await aio_jikan.season(year=year, season=season)

            for item in season_year['anime']:
                title = item['title']
                title_tag = ('_'.join(re.findall(r'\W?(\w+)\W?',
                                                 title))).lower()
                recid = recid_gen()
                record = {
                    'recordid': recid,
                    'username': '******',
                    'record_headline': title,
                    'record_text': f'{title} ({season} {year})'
                }
                tags = [title_tag, str(year), season]
                await write_data_to_db(record, recid, tags, db=db)

    await aio_jikan.close()
    await pg_pool.close()
Exemple #13
0
async def anime(client, message, *args):
    if len(args) == 0:
        await message.channel.send(f"Usage: {PREFIX}anime <anime name>")
        return
    search_str = " ".join(args)
    if len(search_str) < 3:
        await message.channel.send("Anime name must be atleast 3 letters.")
        return
    jikan = AioJikan()
    _search_result = await jikan.search(search_type="anime", query=search_str)
    search_result = _search_result["results"][0]["mal_id"]
    embed = await make_anime_embed(client.loop, search_result, message.author.color)
    await message.channel.send(embed=embed)
Exemple #14
0
    async def character(self, ctx, *, query: str):
        _jikan = AioJikan()
        while len(query) < 3:
            query += ' '

        try:
            async with ctx.typing():
                search = await _jikan.search(search_type='character',
                                             query=query)
                char = await _jikan.character(search['results'][0]['mal_id'])

                title = char[
                    'name'] + f" ({', '.join(char['nicknames'])})" if char[
                        'nicknames'] else char['name']
                about = clean(char['about'])
                about = about if len(about) < 1024 else about[0:1021] + '...'
                anime = '\n'.join([
                    role['name'] + f" ({role['role']})"
                    for role in char['animeography']
                ]) if char['animeography'] else '-'
                manga = '\n'.join([
                    role['name'] + f" ({role['role']})"
                    for role in char['mangaography']
                ]) if char['mangaography'] else '-'
                seiyuu = '\n'.join([
                    person['name'] + f" ({person['language']})"
                    for person in char['voice_actors']
                ]) if char['voice_actors'] else '-'

                char_embed = Embed(color=0x00ff00,
                                   title=title,
                                   url=char['url'])
                char_embed.set_image(url=char['image_url'])
                char_embed.add_field(name='About', value=about, inline=False)
                char_embed.add_field(name='Anime',
                                     value=anime[0:1024],
                                     inline=False)
                char_embed.add_field(name='Manga',
                                     value=manga[0:1024],
                                     inline=False)
                char_embed.add_field(name='Seiyuu', value=seiyuu, inline=False)

                result = await ctx.send(embed=char_embed)
        except APIException:
            result = await ctx.send(embed=wibu_404('Karakter'))
        finally:
            await result.add_reaction('❗')
            await _jikan.close()
Exemple #15
0
async def mal_upcoming(c: Korone, m: Message):
    async with AioJikan() as jikan:
        pass

    upcoming = await jikan.top("anime", page=1, subtype="upcoming")
    await jikan.close()

    upcoming_list = [entry["title"] for entry in upcoming["top"]]
    upcoming_message = "<b>Próximos animes:</b>\n"

    for entry_num in range(len(upcoming_list)):
        if entry_num == 10:
            break
        upcoming_message += f"<b>{entry_num + 1}.</b> {upcoming_list[entry_num]}\n"

    await m.reply_text(upcoming_message)
Exemple #16
0
 async def anime(self, ctx, *, query):
     async with AioJikan() as a:
         naruto = await a.search(search_type='anime', query=query)
     res = naruto['results'][0]
     o = []
     embed = discord.Embed(color=self.bot.colour)
     embed.set_thumbnail(url=res['image_url'])
     embed.title = f"{res['title']}"
     embed.url = f"{res['url']}"
     embed.description = f"{naruto['results'][0]['synopsis']}"
     embed.add_field(name="Info",
                     value=f"Type | **{res['type']}**\n📺 | **{res['episodes']}**\n:star:️ | **{res['score']}**\n<:member:731190477927219231> | **{res['members']:,}**")
     for x in range(2, len(naruto['results'])):
         o.append(f"**{naruto['results'][x]['title']}**")
     embed.add_field(name="Other Entries", value=f"\n".join(o[:5]))
     await ctx.send(embed=embed)
Exemple #17
0
async def upcoming(message):
    async with AioJikan() as jikan:
        pass

    upcoming = await jikan.top("anime", page=1, subtype="upcoming")
    await jikan.close()

    upcoming_list = [entry["title"] for entry in upcoming["top"]]
    upcoming_message = ""

    for entry_num in range(len(upcoming_list)):
        if entry_num == 10:
            break
        upcoming_message += f"{entry_num + 1}. {upcoming_list[entry_num]}\n"

    await message.reply(upcoming_message)
Exemple #18
0
    async def anime_search(self, ctx: commands.Context, *,
                           keyword: str) -> None:
        """Searches for anime information."""

        loading_msg = await ctx.send(embed=Embed("Searching..."))

        jikan = AioJikan()
        results = (await jikan.search(search_type="anime",
                                      query=keyword))['results']

        if not results:
            await ctx.send(embed=Embed("Anime not found."), delete_after=5)
            return

        anime = await jikan.anime(results[0]['mal_id'])
        await jikan.close()

        if anime['title_english'] and not anime['title_japanese']:
            title = anime['title_english']
        elif not anime['title_english'] and anime['title_japanese']:
            title = anime['title_japanese']
        else:
            title = f"{anime['title_english']} ({anime['title_japanese']})"

        embed = Embed()
        embed.set_author(name=title, url=anime['url'])
        embed.set_thumbnail(url=anime['image_url'])
        embed.set_footer(
            text="Powered by MyAnimeList",
            icon_url=ICONS['myanimelist'],
        )
        embed.add_field(
            name="Synopsis",
            value=anime['synopsis'][:1000] +
            "..." if len(anime['synopsis']) > 1000 else anime['synopsis'],
            inline=False)
        embed.add_field("Episodes", anime['episodes'])
        embed.add_field("Rank", anime['rank'])
        embed.add_field("Status", anime['status'])
        embed.add_field("Aired", anime['aired']['string'])
        embed.add_field(
            "Genres", ", ".join([genre['name'] for genre in anime['genres']]))

        await self.bot.delete_message(loading_msg)
        await ctx.send(embed=embed)
Exemple #19
0
 async def mal(self, ctx, *, anime):
     jikan = AioJikan(loop=asyncio.get_event_loop())
     result = await jikan.search(search_type='anime', query=anime)
     await jikan.close()
     img_url = result['results'][0]['image_url']
     title = result['results'][0]['title']
     desc = result['results'][0]['synopsis']
     episode_count = result['results'][0]['episodes']
     score = result['results'][0]['score']
     url = result['results'][0]['url']
     embed = discord.Embed(colour=discord.Colour.from_rgb(46, 81, 162),
                           url=url,
                           title=title,
                           description=desc)
     embed.add_field(name='Episodes:', value=episode_count, inline=False)
     embed.add_field(name='Score:', value=score, inline=False)
     embed.set_thumbnail(url=img_url)
     await ctx.send(embed=embed)
Exemple #20
0
    async def manga(self, ctx, *, query: str):
        _jikan = AioJikan()
        while len(query) < 3:
            query += ' '

        try:
            async with ctx.typing():
                search = await _jikan.search(search_type='manga', query=query)
                manga = await _jikan.manga(search['results'][0]['mal_id'])

                title = manga[
                    'title'] + f" ({manga['title_japanese']})" if manga[
                        'title_japanese'] else manga['title']
                synopsis = manga['synopsis'] if manga['synopsis'] and len(
                    manga['synopsis']
                ) < 1024 else manga['synopsis'][0:1021] + '...'
                rank = '#' + str(manga['rank'])
                popularity = '#' + str(manga['popularity'])
                genres = ', '.join(
                    [genre['name'] for genre in manga['genres']])

                manga_embed = Embed(title=title, url=manga['url'])
                manga_embed.set_thumbnail(url=manga['image_url'])
                manga_embed.add_field(name='Synopsis',
                                      value=synopsis,
                                      inline=False)
                manga_embed.add_field(name='Status', value=manga['status'])
                manga_embed.add_field(name='Total Volumes' if manga['status']
                                      == 'Finished' else 'Latest Volume',
                                      value=manga['volumes'])
                manga_embed.add_field(name='Total Chapters' if manga['status']
                                      == 'Finished' else 'Latest Chapter',
                                      value=manga['chapters'])
                manga_embed.add_field(name='Score', value=manga['score'])
                manga_embed.add_field(name='Ranking', value=rank)
                manga_embed.add_field(name='Popularity', value=popularity)
                manga_embed.add_field(name='Genre', value=genres, inline=False)

                result = await ctx.send(embed=manga_embed)
        except APIException:
            result = await ctx.send(embed=wibu_404('Manga'))
        finally:
            await result.add_reaction('❗')
            await _jikan.close()
Exemple #21
0
async def manga(client, message, *args):
    if len(args) == 0:
        await message.channel.send(f"Usage: {PREFIX}manga <manga name>")
        return
    search_str = " ".join(args)
    if len(search_str) < 3:
        await message.channel.send("Manga name must be atleast 3 letters.")
        return
    jikan = AioJikan()
    _search_result = await jikan.search(search_type="manga", query=search_str)
    search_result = _search_result["results"][0]["mal_id"]
    manga = await jikan.manga(search_result)
    synopsis = manga["synopsis"]
    if len(synopsis) > 1500:
        synopsis = synopsis[:1500] + "..."
    embed = discord.Embed(
        title=manga["title"],
        description=synopsis,
        url=manga["url"],
        color=message.author.colour,
    )
    if "image_url" in manga.keys() and manga["image_url"]:
        embed.set_image(url=manga["image_url"])
    embed.add_field(name="Type", value=manga["type"])
    embed.add_field(
        name="Chapters", value=f"{manga['chapters']} ({manga['volumes']} volumes)"
    )
    embed.add_field(name="Status", value=manga["status"])
    embed.add_field(name="Published", value=manga["published"]["string"])
    embed.add_field(name="Rank", value=manga["rank"])
    embed.add_field(
        name="Score", value=f"{manga['score']} by {manga['scored_by']} members"
    )
    genres = ", ".join([g["name"] for g in manga["genres"]])
    embed.add_field(name="Genres", value=genres, inline=True)
    if "Adaptation" in manga["related"].keys():
        adaptations = ", ".join(
            [f"{i['name']} ({i['type']})" for i in manga["related"]["Adaptation"]]
        )
        embed.add_field(name="Adaptations", value=adaptations, inline=True)
    embed.set_footer(text="Taken from MyMangaList.net")
    await message.channel.send(embed=embed)
Exemple #22
0
    async def anime_upcoming(self, ctx: commands.Context) -> None:
        """Lists upcoming anime."""

        jikan = AioJikan()
        result = (await jikan.season_later())['anime']
        await jikan.close()

        embeds = []
        for i in range(0, len(result), 10):
            temp = []
            for index, value in enumerate(result[i:i + 10], i):
                temp.append(
                    f"`{index + 1}.` [{value['title']}]({value['url']})")
            embeds.append(Embed("\n".join(temp)))

        pagination = PaginationEmbed(ctx, embeds=embeds)
        pagination.embed.title = ":clock3: Upcoming Anime"
        pagination.embed.set_footer(
            text="Powered by MyAnimeList",
            icon_url=ICONS['myanimelist'],
        )
        await pagination.build()
Exemple #23
0
async def mal_character(e):
    await e.edit('Searching...')
    await e.delete()
    async with AioJikan() as jikan:
        sr = await jikan.search('character', e.pattern_match.group(1))
        c = await jikan.character(sr['results'][0]['mal_id'])
    if not c:
        await e.reply('err \\\nNo results found')
        return
    text = f'<b>{html.escape(c["name"])}'
    if c['name_kanji']:
        text += f' ({html.escape(c["name_kanji"])})'
    text += '</b>\n'
    about = html.escape(c['about'].replace('\\n', ''))
    text += f'<i>{about}</i>\n'
    pic = f'{c["image_url"]}'
    url = f'<a href="{html.escape(c["url"])}">read more</a>'
    text = text.strip()
    if len(text) > 1024:
        text = text[0:500] + ".... "
    text = text + url
    await e.reply(text, file=pic, link_preview=False, parse_mode='html')
Exemple #24
0
async def mal_manga(event):
    """Search manga from Kantek itself
       Powered by jikan.moe

    Examples:
        {cmd} command
    """
    async with AioJikan() as jikan:
        sr = await jikan.search('manga', event.text.split(" ", 1))
        m = await jikan.manga(sr['results'][0]['mal_id'])
    if not m:
        await event.reply('err \\\nNo results found')
        return
    text = f'<b>{html.escape(m["title"])}'
    if m['title_japanese']:
        text += f' ({html.escape(m["title_japanese"])})'
    text += '</b>\n'
    text += f'<b>Score:</b> {m["score"]}\n'
    text += f'<b>Type:</b> {html.escape(m["type"])}\n'
    text += f'<b>Genres:</b> {", ".join([html.escape(i["name"]) for i in m["genres"]])}\n'
    text += f'<b>Status:</b> {html.escape(m["status"])}\n'
    if m['volumes']:
        text += f'<b>Volumes:</b> {m["volumes"]}\n'
    if m['chapters']:
        text += f'<b>Chapters:</b> {m["chapters"]}\n'
    text += f'<i>{html.escape(m["synopsis"])}</i>\n'
    pic = f'{m["image_url"]}'
    url = f'<a href="{html.escape(m["url"])}">read more</a>'
    text = text.strip()
    if len(text) > 1024:
        text = text[0:500] + ".... "
    text = text + url
    try:
        await event.reply(text,
                          file=pic,
                          link_preview=False,
                          parse_mode='html')
    except BaseException:
        await event.reply(text, link_preview=False, parse_mode='html')
Exemple #25
0
    async def mal(self, ctx, *, query):
        jikan = AioJikan()

        try:
            result = await jikan.search("anime", query)
        except APIException:
            await ctx.send("Problem connecting to the API. Please try again.")
            await jikan.close()
            return

        #taking first result for now
        if len(result["results"]) > 0:
            result = result["results"][0]
        else:
            await ctx.send(f"No results for <{query}>.")
            await jikan.close()
            return

        try:
            anime = await jikan.anime(result.get("mal_id"))
        except APIException:
            await ctx.send("Problem connecting to the API. Please try again.")
            await jikan.close()
            return

        title = anime.get("title")
        title_japanese = anime.get("title_japanese")
        anime_type = anime.get("type")
        url = anime.get("url")
        image = anime.get("image_url")
        airing = anime.get("airing")
        aired = anime["aired"].get("string")
        synopsis = anime.get("synopsis")
        score = anime.get("score")
        broadcast = "N/A"
        if airing:
            broadcast = anime.get("broadcast")
        if (episodes := anime.get("episodes")) is None:
            episodes = "N/A"
Exemple #26
0
    async def random_async(profile, pages=8):
        async with AioJikan() as jikan:

            if profile:
                person_list = await jikan.user(profile, request='animelist')
                anime = await jikan.anime(
                    rnd.choice(person_list['anime'])['mal_id'])

            else:
                pages = 8 if pages < 1 else pages
                page_no = rnd.randint(1, pages)
                item_no = rnd.randint(0, 49)

                page = await jikan.top('anime',
                                       page=page_no,
                                       subtype='bypopularity')
                anime = await jikan.anime(page['top'][item_no]['mal_id'])

            try:
                return Entry(anime)

            except AssertionError:
                return await Entry.random_async(profile, pages)
Exemple #27
0
from jikanpy import AioJikan
import asyncio
from pprint import pprint

loop = asyncio.get_event_loop()

aio_jikan = AioJikan(loop=loop)


async def main(loop):
    mushishi = await aio_jikan.anime(457)
    pprint(mushishi)

    fma = await aio_jikan.manga(25)
    pprint(fma)

    ginko = await aio_jikan.character(425)
    pprint(ginko)

    naruto = await aio_jikan.search(search_type='anime', query='naruto')
    pprint(naruto)

    winter_2018 = await aio_jikan.season(year=2018, season='winter')
    pprint(winter_2018)

    monday = await aio_jikan.schedule(day='monday')
    pprint(monday)

    top_anime = await aio_jikan.top(type='anime')
    pprint(top_anime)
Exemple #28
0
 def __init__(self, bot):
     self.bot = bot
     self.neko_client = NekoClient(self.bot.aiohttp_session, self.bot.loop)
     self.jikan = AioJikan(session=self.bot.aiohttp_session,
                           loop=self.bot.loop)
Exemple #29
0
async def profile(client, message, *args):
    if len(args) == 0:
        await message.channel.send(f"Usage: {PREFIX}profile <MAL User>")
        return
    search_str = " ".join(args)
    try:
        jikan = AioJikan()
        profile = await jikan.user(username=search_str, request="profile")
    except APIException:
        await message.channel.send("Username not found on MAL, or account is private.")
        return
    embed = discord.Embed(
        title="{0}'s MAL Profile".format(search_str),
        url=profile["url"],
        color=message.author.colour,
    )
    if profile["image_url"]:
        embed.set_thumbnail(url=profile["image_url"])
    if profile["gender"]:
        embed.add_field(name="Gender", value=profile["gender"])
    if profile["birthday"]:
        birthday = datetime.datetime.fromisoformat(profile["birthday"]).strftime(
            "%A, %d %B, %Y"
        )
        embed.add_field(name="Birthday", value=birthday)
    if profile["location"]:
        embed.add_field(name="Location", value=profile["location"])
    if profile["joined"]:
        joined = datetime.datetime.fromisoformat(profile["joined"]).strftime(
            "%A, %d %B, %Y"
        )
        embed.add_field(name="Joined MAL", value=joined)
    astats = profile["anime_stats"]
    anime_stats = f"""
Days of anime watched: {astats['days_watched']}
Mean score: {astats['mean_score']}
Watching: {astats['watching']}
Completed: {astats['completed']}
On Hold: {astats['on_hold']}
Dropped: {astats['dropped']}
Plan to Watch: {astats['plan_to_watch']}
Rewatched: {astats['rewatched']}
Episodes Watched: {astats['episodes_watched']}
Total: {astats['total_entries']}
    """
    mstats = profile["manga_stats"]
    manga_stats = f"""
Days of manga read: {mstats['days_read']}
Mean score: {mstats['mean_score']}
Reading: {mstats['reading']}
Completed: {mstats['completed']}
On Hold: {mstats['on_hold']}
Dropped: {mstats['dropped']}
Plan to Read: {mstats['plan_to_read']}
Reread: {mstats['reread']}
Chapters Read: {mstats['chapters_read']}
Volumes Read: {mstats['volumes_read']}
Total: {mstats['total_entries']}
    """
    embed.add_field(name="Anime Stats", value=anime_stats, inline=False)
    embed.add_field(name="Manga Stats", value=manga_stats, inline=False)
    if profile["favorites"]["anime"]:
        afavs = profile["favorites"]["anime"]
        anime_favorites = ", ".join(
            [
                "[{0}]({1})".format(
                    i["name"].replace(",", ""), i["url"].replace("_", r"\_")
                )
                for i in afavs
            ]
        )
    else:
        anime_favorites = "No anime favorites set."
    if profile["favorites"]["manga"]:
        mfavs = profile["favorites"]["manga"]
        manga_favorites = ", ".join(
            [
                "[{0}]({1})".format(
                    i["name"].replace(",", ""), i["url"].replace("_", r"\_")
                )
                for i in mfavs
            ]
        )
    else:
        manga_favorites = "No manga favorites set."
    if profile["favorites"]["characters"]:
        cfavs = profile["favorites"]["characters"]
        favorite_chars = ", ".join(
            [
                "[{0}]({1})".format(
                    i["name"].replace(",", ""), i["url"].replace("_", r"\_")
                )
                for i in cfavs
            ]
        )
    else:
        favorite_chars = "No favorite characters set."
    embed.add_field(name="Anime Favorites", value=anime_favorites, inline=False)
    embed.add_field(name="Manga Favorites", value=manga_favorites, inline=False)
    embed.add_field(name="Favorite Characters", value=favorite_chars, inline=False)
    about = profile["about"]
    if about:
        if len(about) > 500:
            about = about[:500] + "..."
        embed.add_field(name="About Them", value=about)
    await message.channel.send(embed=embed)
Exemple #30
0
async def mangalist(client, message, *args):
    if len(args) == 0:
        await message.channel.send(f"Usage: {PREFIX}mangalist <MAL User>")
        return
    search_str = " ".join(args)
    try:
        jikan = AioJikan()
        raw_mangalist = await jikan.user(username=search_str, request="mangalist")
    except APIException:
        await message.channel.send("Username not found on MAL, or account is private.")
        return
    mangalist = raw_mangalist["manga"]
    sentences = []
    for i, manga in enumerate(mangalist):
        reading_status = manga["reading_status"]
        if reading_status == 1:
            status = f"Currently Reading ({manga['read_chapters']}/{manga['total_chapters']} chaps)"
        elif reading_status == 2:
            status = (
                f"Completed ({manga['read_chapters']}/{manga['total_chapters']} chaps)"
            )
        elif reading_status == 3:
            status = (
                f"On Hold ({manga['read_chapters']}/{manga['total_chapters']} chaps)"
            )
        elif reading_status == 4:
            status = (
                f"Dropped ({manga['read_chapters']}/{manga['total_chapters']} chaps)"
            )
        elif reading_status == 6:
            status = "Plan To Read"
        sentences.append(
            "{0}. **__[{1}]({2})__**. Status: **{3}**. Score: **{4}**.".format(
                i + 1,
                manga["title"],
                manga["url"].replace("_", r"\_"),
                status,
                manga["score"],
            )
        )
    pages = list(chunks(sentences, 15))
    page_num = 1
    total_pages = len(pages)
    embed = discord.Embed(
        title=f"{search_str}'s MangaList",
        color=message.author.colour,
        description="\n".join(pages[page_num - 1]),
    )
    embed.add_field(name="Total Manga", value=len(mangalist))
    embed.set_footer(text=f"Page: {page_num}/{total_pages}")
    msg = await message.channel.send(embed=embed)
    if total_pages == 1:
        return
    await msg.add_reaction("⬅")
    await msg.add_reaction("➡")
    try:
        while True:

            def check(reaction, user):
                emoji = str(reaction.emoji)
                return not user.bot and (emoji == "⬅" or emoji == "➡")

            reaction, _ = await client.wait_for(
                "reaction_add", timeout=300, check=check
            )
            emoji = str(reaction.emoji)
            if emoji == "⬅":
                if not page_num - 1 > 0:
                    continue
                page_num -= 1
                embed.description = "\n".join(pages[page_num - 1])
            elif emoji == "➡":
                if not page_num + 1 <= total_pages:
                    continue
                page_num += 1
                embed.description = "\n".join(pages[page_num - 1])
            else:
                continue
            embed.set_footer(text=f"Page: {page_num}/{total_pages}")
            await msg.edit(embed=embed)
    except asyncio.TimeoutError:
        pass  # Ignore.