コード例 #1
0
    async def mal(self, ctx, username: str = None):
        """
            {command_prefix}mal (username)

        {help}
        """
        if not username:
            username = ctx.author.name
        await ctx.trigger_typing()
        try:
            result = await self.bot.jikan.user(username=username)
        except (JikanException, aiohttp.ClientError):
            return await ctx.send(get_str(ctx, "no-result"))
        result = Jikan(result)
        embed = discord.Embed()
        stats = result.anime_stats
        embed.add_field(name='Completed', value=stats.completed)
        embed.add_field(name='Watching', value=stats.watching)
        embed.add_field(name='On hold', value=stats.on_hold)
        embed.add_field(name='Dropped', value=stats.dropped)
        embed.add_field(name='Plan to Watch', value=stats.plan_to_watch)
        embed.add_field(name='Rewatched', value=stats.rewatched)
        embed.add_field(name='Mean Score', value=stats.mean_score)
        embed.add_field(name='Total', value=stats.total_entries)
        embed.add_field(name='Episodes Watched', value=stats.episodes_watched)
        embed.add_field(name='Days Watched', value=stats.days_watched)

        embed.set_author(name=result.username,
                         url=result.url,
                         icon_url='https://i.imgur.com/vEy5Zaq.png')
        embed.set_thumbnail(url=result.image_url)
        await ctx.send(embed=embed)
コード例 #2
0
    async def nextep(self, ctx, *, anime: str):
        """
            {command_prefix}nextep [anime_title]

        {help}
        """
        search = await ctx.send(get_str(ctx, "is-searching"))
        await ctx.trigger_typing()
        found = await self.google_results('anime', anime)
        if not found:
            return await ctx.send(get_str(ctx, "no-result"))
        try:
            selection = await self.bot.jikan.anime(found)
            anime = Jikan(selection)
        except (JikanException, aiohttp.ClientError):
            return await ctx.send(get_str(ctx, "no-result"))

        if anime.status == "Finished Airing":
            aired = anime.aired
            a = getattr(aired, 'from').split('T')[0]
            if aired.to:
                b = getattr(aired, 'to').split('T')[0]
            else:
                b = '?'
            aired = get_str(ctx, "cmd-anime-aired") + \
                f" : **{a}** " + get_str(ctx, "cmd-anime-to") + f" **{b}**"
            remaining = get_str(ctx, "cmd-nextep-not-airing") + f"\n{aired}"
        else:
            try:
                remaining = await self.get_remaining_time(anime, ctx)
            except ValueError:
                remaining = '?'
        embed = discord.Embed(title=get_str(ctx, "cmd-nextep"),
                              description=remaining,
                              color=0x0066CC)
        embed.set_author(name='{}'.format(anime.title),
                         url=anime.url,
                         icon_url='https://i.imgur.com/vEy5Zaq.png')
        embed.set_thumbnail(url=anime.image_url)

        embed.set_footer(text=get_str(ctx, "cmd-anime-aired", can_owo=False) +
                         " : " + (anime.broadcast or '?'))
        try:
            await search.delete()
        except discord.HTTPException:
            pass
        try:
            await ctx.send(embed=embed)
        except discord.Forbidden:
            return await ctx.send(get_str(ctx, "need-embed-permission"))
コード例 #3
0
ファイル: blindTestSong.py プロジェクト: Zenrac/Watora
    async def add_alternative_titles(self, optional=[]):
        if optional:
            if isinstance(optional, list):
                self._titles += optional
            else:
                self._titles += [optional]
        if self.is_anime:
            if not self.alternative_added:
                settings = await SettingsDB.get_instance().get_glob_settings()
                if str(self.id) in settings.cachedanimes:
                    self._titles += settings.cachedanimes[str(self.id)]
                    self.alternative_added = True
                else:
                    for m in range(6):
                        try:
                            selection = await asyncio.wait_for(
                                self.jikan.anime(self.id), timeout=m + 2)
                            break
                        except (asyncio.TimeoutError, JikanException,
                                aiohttp.ClientError):
                            selection = False

                    if selection:
                        selection = Jikan(selection)
                        altenatives = [
                            selection.title, selection.title_english,
                            selection.title_japanese
                        ]
                        altenatives += selection.title_synonyms
                        settings.cachedanimes[str(self.id)] = altenatives
                        await SettingsDB.get_instance().set_glob_settings(
                            settings)
                        self._titles += altenatives
                        self.alternative_added = True

        self._titles += [self.title]
        titles = self._titles.copy()

        for m in range(10):
            new_titles = self.generate_anwers(titles)
            if new_titles == titles:
                break
            titles = new_titles

        self._titles = titles
コード例 #4
0
    async def anime(self, ctx, *, anime: str):
        """
            {command_prefix}anime [anime_title]

        {help}
        """
        fetch = await ctx.send(get_str(ctx, "is-searching"))
        await ctx.trigger_typing()
        found = await self.google_results('anime', anime)
        if not found:
            return await ctx.send(get_str(ctx, "no-result"))
        try:
            selection = await self.bot.jikan.anime(found)
            selection = Jikan(selection)
        except (JikanException, aiohttp.ClientError):
            return await ctx.send(get_str(ctx, "no-result"))

        em = discord.Embed(colour=0x0066CC)
        synopsis = selection.synopsis
        if synopsis:
            synopsis = self.remove_html(synopsis)
            if len(synopsis) > 300:
                em.description = " ".join(synopsis.split(
                    " ")[0:40]) + "[ Read more»](%s)" % selection.url
        em.set_author(name=selection.title,
                      url=selection.url,
                      icon_url='https://i.imgur.com/vEy5Zaq.png')
        if selection.title_english:
            if selection.title_english.lower() not in selection.title.lower():
                em.add_field(name=get_str(ctx, "cmd-anime-english-title"),
                             value=selection.title_english,
                             inline=False)
        try:
            em.add_field(name="{}".format(
                get_str(ctx, "cmd-anime-episodes") if int(selection.episodes) >
                1 else get_str(ctx, "cmd-anime-episode")),
                         value=selection.episodes)
        except TypeError:
            pass
        em.add_field(name=get_str(ctx, "cmd-anime-type"), value=selection.type)
        em.add_field(name=get_str(ctx, "cmd-anime-ranked"),
                     value=("#" +
                            str(selection.rank)) if selection.rank else 'N/A')
        em.add_field(name=get_str(ctx, "cmd-anime-popularity"),
                     value=("#" + str(selection.popularity))
                     if selection.popularity else 'N/A')
        score = round((selection.score or 0), 2)
        if score == 0:
            score = "N/A"
        em.add_field(name=get_str(ctx, "cmd-anime-score"), value=score)
        em.set_thumbnail(url=selection.image_url)
        status = selection.status
        em.add_field(name=get_str(ctx, "cmd-anime-status"), value=status)
        aired = selection.aired
        a = getattr(aired, 'from').split('T')[0]
        if aired.to:
            b = getattr(aired, 'to').split('T')[0]
        else:
            b = '?'
        aired = get_str(ctx, "cmd-anime-aired-from", can_owo=False) + " " + \
            a + " " + get_str(ctx, "cmd-anime-to", can_owo=False) + " " + b
        em.set_footer(text=aired)
        try:
            await fetch.delete()
        except discord.HTTPException:
            pass
        try:
            await ctx.send(embed=em)
        except discord.Forbidden:
            return await ctx.send(get_str(ctx, "need-embed-permission"))
コード例 #5
0
    async def chara(self, ctx, *, chara: str):
        """
            {command_prefix}char [char_name]

        {help}
        """
        fetch = await ctx.send(get_str(ctx, "is-searching"))
        await ctx.trigger_typing()
        found = await self.google_results('character', chara)
        if not found:
            return await ctx.send(get_str(ctx, "no-result"))
        try:
            selection = await self.bot.jikan.character(found)
            selection = Jikan(selection)
        except (JikanException, aiohttp.ClientError):
            return await ctx.send(get_str(ctx, "no-result"))

        em = discord.Embed(colour=0x0066CC)
        try:
            em.add_field(name='Anime',
                         value=selection.animeography[0].name,
                         inline=False)
        except (IndexError, AttributeError):
            try:
                em.add_field(name='Manga',
                             value=selection.mangaography[0].name,
                             inline=False)
            except (IndexError, AttributeError):
                pass
        try:
            lenght = len(list(selection.voice_actors))
            va = list(selection.voice_actors)[0].name
            for m in selection.voice_actors:
                if m.language == "Japanese":
                    va = m.name
                    break
        except (IndexError, AttributeError):
            va = "No info"

        em.add_field(name=get_str(ctx, "cmd-char-seiyuu"), value=va)

        try:
            em.add_field(name="{}".format(
                get_str(ctx, "cmd-char-favorites") if selection.
                member_favorites > 1 else get_str(ctx, "cmd-char-favorite")),
                         value=selection.member_favorites,
                         inline=False)
        except (IndexError, AttributeError):
            pass
        em.set_image(url=selection.image_url)
        em.set_author(name=selection.name,
                      url=selection.url,
                      icon_url='https://i.imgur.com/vEy5Zaq.png')
        try:
            await fetch.delete()
        except discord.HTTPException:
            pass
        try:
            await ctx.send(embed=em)
        except discord.Forbidden:
            return await ctx.send(get_str(ctx, "need-embed-permission"))