CTK-WARRIOR / ctk-anime-scraper

scraper to scrap anime from gogoanime
12 stars 2 forks source link

AnimeAPI Searching Issue #6

Closed xaxa-0x3F closed 3 years ago

xaxa-0x3F commented 3 years ago
const animeapi = require('ctk-anime-scraper');
        const { MessageEmbed, MessageAttachment, MessageCollector } = require('discord.js');

        const name = message.content
        .match(/(?:"[^"]*"|^[^"]*$)/)[0]
        .replace(/"/g, "")

        let ep = /^\d+|\d+\b|\d+(?=\w)/g[0];
        let rgx = /\d/;
        let mez = message.content;

        if(rgx.test(mez) == false){
            const test = await animeapi.search(name).then((data) => {
                if(!data.length) return console.log("No Anime with this name found")
                let ani = new MessageEmbed()
                .addField('Link:', `[Click to watch](${data[0].link})`)
                animeapi.fetchAnime(data[0].link, {
                    disableEpisodeFetch: true
                    }).then(data => {
                        ani
                        .setTitle(data.name)
                        .setThumbnail(data.image)
                        .addFields(
                            {name: 'Episodes:', value: data.episodeCount, inline: true},
                            {name: 'Status:', value: data.status, inline: true},
                            {name: 'Type:', value: data.type, inline: true},
                            {name: 'Genre:', value: data.genre, inline: true},
                            {name: 'Released:', value: data.released, inline: true},
                        )
                        message.channel.send(ani)
                    })
            });
        } else {
            console.log('dis do be workin');
            const test = await animeapi.search(name).then((data) => {
            if(!data.length) return message.reply("No Anime with this name found")
                let ani = new MessageEmbed()
                .addField('Link:', `[Click to watch](${data[0].link})`)
                animeapi.fetchAnime(data[0].link, {episode: ep}).then(data => {
                        console.log(data);
                        ani
                        .setTitle(data.name)
                        .setThumbnail(data.image)
                        .addFields(
                            {name: 'Episodes:', value: data.episodeCount, inline: true},
                            {name: 'Status:', value: data.status, inline: true},
                            {name: 'Type:', value: data.type, inline: true},
                            {name: 'Genre:', value: data.genre, inline: true},
                            {name: 'Released:', value: data.released, inline: true},
                        )
                        message.channel.send(ani)
                    }).catch(e => console.log(e));
            });
        }

Hello, I am running this if statement to find the number in a message and no matter what I change (i've tried lots of different options,) when the else statement is triggered there's nothing returning from the api search, however the conosle.log does return which confuses me if you can help I would appreciate it.

CTK-WARRIOR commented 3 years ago

it seems like it has nothing to do with package

JUGisMUG commented 3 years ago

Why you using await and then at the same time while defining test variable..Either use await or then...here's a quick example that might work:

const​ ​test​ ​=​ ​await​ ​animeapi​.​search​(​name);

And now you can test as the fetched data from anime scraper..

And uh if you wanne use then instead of await, then don't put it in a variable and await it, you can simply do:

animeapi.search(name).then(data => {
    //your code here, you can use "data" as the fetched data from anime scraper
});

Hope it helps.

xaxa-0x3F commented 3 years ago

Why you using await and then at the same time while defining test variable..Either use await or then...here's a quick example that might work:

const​ ​test​ ​=​ ​await​ ​animeapi​.​search​(​name);

And now you can test as the fetched data from anime scraper..

And uh if you wanne use then instead of await, then don't put it in a variable and await it, you can simply do:

animeapi.search(name).then(data => {
    //your code here, you can use "data" as the fetched data from anime scraper
});

Hope it helps.

thank you so much for this didn't realize.