示例#1
0
async def buildMangaReplyWithAuthor(searchText,
                                    authorName,
                                    message,
                                    isExpanded,
                                    canEmbed,
                                    blockTracking=False):
    try:
        ani = await Anilist.getMangaWithAuthor(searchText, authorName)
        mal = None
        mu = None
        ap = None

        if ani:
            try:
                mal = await MAL.getMangaCloseToDescription(
                    searchText, ani['description'])
                ap = await AniP.getMangaURL(ani['title_english'], authorName)
            except Exception as e:
                print(e)
        else:
            ap = await AniP.getMangaURL(searchText, authorName)

        mu = await MU.getMangaWithAuthor(searchText, authorName)

        if ani:
            try:
                titleToAdd = ''
                if mal is not None:
                    titleToAdd = mal['title']
                else:
                    titleToAdd = ani['title_english']

                if not blockTracking:
                    DatabaseHandler.addRequest(titleToAdd, 'Manga',
                                               message.author.id,
                                               message.server.id)
            except:
                traceback.print_exc()
                pass

            if not canEmbed:
                return CommentBuilder.buildMangaComment(
                    isExpanded, mal, ani, mu, ap)
            else:
                return CommentBuilder.buildMangaEmbed(isExpanded, mal, ani, mu,
                                                      ap)

    except Exception as e:
        traceback.print_exc()
        return None
示例#2
0
async def buildMangaReply(searchText,
                          message,
                          isExpanded,
                          canEmbed,
                          blockTracking=False):
    try:
        ani = None
        mal = None
        mu = None
        ap = None

        try:
            sqlCur.execute(
                'SELECT dbLinks FROM synonyms WHERE type = "Manga" and lower(name) = ?',
                [searchText.lower()])
        except sqlite3.Error as e:
            print(e)

        alternateLinks = sqlCur.fetchone()

        if (alternateLinks):
            synonym = json.loads(alternateLinks[0])

            if 'mal' in synonym:
                if (synonym['mal']):
                    mal = await MAL.getMangaDetails(synonym['mal'][0],
                                                    synonym['mal'][1])

            if 'ani' in synonym:
                if (synonym['ani']):
                    ani = await Anilist.getMangaDetailsById(synonym['ani'])

            if 'mu' in synonym:
                if (synonym['mu']):
                    mu = MU.getMangaURLById(synonym['mu'])

            if 'ap' in synonym:
                if (synonym['ap']):
                    ap = AniP.getMangaURLById(synonym['ap'])

        else:
            #Basic breakdown:
            #If Anilist finds something, use it to find the MAL version.
            #If hits either MAL or Ani, use it to find the MU version.
            #If it hits either, add it to the request-tracking DB.
            ani = await Anilist.getMangaDetails(searchText)

            if ani:
                try:
                    mal = await MAL.getMangaDetails(ani['title_romaji'])
                except Exception as e:
                    print(e)
                    pass

                if not mal:
                    try:
                        mal = await MAL.getMangaDetails(ani['title_english'])
                    except:
                        pass

                if not mal:
                    mal = await MAL.getMangaDetails(searchText)

            else:
                mal = await MAL.getMangaDetails(searchText)

                if mal:
                    ani = await Anilist.getMangaDetails(mal['title'])

        #----- Finally... -----#
        if ani or mal:
            try:
                titleToAdd = ''
                if mal:
                    titleToAdd = mal['title']
                else:
                    try:
                        titleToAdd = ani['title_english']
                    except:
                        titleToAdd = ani['title_romaji']

                if not alternateLinks:
                    #MU stuff
                    if mal:
                        mu = await MU.getMangaURL(mal['title'])
                    else:
                        mu = await MU.getMangaURL(ani['title_romaji'])

                    #Do the anime-planet stuff
                    if mal and not ap:
                        if mal['title'] and not ap:
                            ap = await AniP.getMangaURL(mal['title'])
                        if mal['english'] and not ap:
                            ap = await AniP.getMangaURL(mal['english'])
                        if mal['synonyms'] and not ap:
                            for synonym in mal['synonyms']:
                                if ap:
                                    break
                                ap = await AniP.getMangaURL(synonym)

                    if ani and not ap:
                        if ani['title_english'] and not ap:
                            ap = await AniP.getMangaURL(ani['title_english'])
                        if ani['title_romaji'] and not ap:
                            ap = await AniP.getMangaURL(ani['title_romaji'])
                        if ani['synonyms'] and not ap:
                            for synonym in ani['synonyms']:
                                if ap:
                                    break
                                ap = await AniP.getMangaURL(synonym)
                if not blockTracking:
                    DatabaseHandler.addRequest(titleToAdd, 'Manga',
                                               message.author.id,
                                               message.server.id)
            except:
                traceback.print_exc()
                pass
        if mal:
            try:
                DatabaseHandler.addMalEntry('malmanga', mal)
            except:
                traceback.print_exc()
                pass
        if ani:
            try:
                DatabaseHandler.addAniEntry('anilistmanga', ani)
            except:
                traceback.print_exc()
                pass
        if not canEmbed:
            return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu,
                                                    ap)
        else:
            return CommentBuilder.buildMangaEmbed(isExpanded, mal, ani, mu, ap)
    except Exception as e:
        traceback.print_exc()
        return None