AtoraSuunva / booru

Searches boorus for images using some js magic
https://www.npmjs.com/package/booru
MIT License
75 stars 18 forks source link

rating:questionable not working for danbooru #24

Closed HLA-systeem closed 5 years ago

HLA-systeem commented 5 years ago

rating:safe danbooru images work, as do rating:questionable images for yande.re and konachan.com. But this rating doesn't return anything for Danbooru specifically

My code if you believe it's on my end:

const BOORU = require('booru');

module.exports.run = async (bot,message,args) => {
    let site;
    let tag = args[1]
    let notPicked = false

    switch(args[0]) {
        case "dan":
          site = 'danbooru'
          break;
        case "yan":
          site = 'yande.re'
          break;
        case "kon":
          site = 'konachan.com'
          break;
        default:
            message.channel.send("Please pick a supported site :^)");
            notPicked = true
      }

      if(!notPicked){
        if(args[1] == "nsfw"){
            tag = args[2]

            if(tag == "guro" || tag == "loli" || tag == "despacito"){
                message.channel.send("https://www.betterhelp.com/");
            }
            else{
                if(message.channel.nsfw == true ){
                    rando = Math.floor(Math.random() * 5);
                    let rating = "rating:questionable";

                    if (rando == 0){
                        rating = 'rating:explicit';
                    }

                    BOORU.search(site, [rating,tag], {random:true})
                    .then(
                        (images) => {
                            let index = Math.floor(Math.random() * images.length); // Select a random imagefrom images array
                            let image = images[index];
                            let url = image.common.file_url;
                            message.channel.send(url);
                        }
                    )
                    .catch(err => message.channel.send("Nothing turned up."));         
                }
                else{
                    message.channel.send("Go to a NSFW channel first :^)");
                }
            }
        }
        else{
            console.log(tag)

            BOORU.search(site, ['rating:safe',tag], {random:true})
            .then(
                (images) => {
                    let index = Math.floor(Math.random() * images.length); // Select a random imagefrom images array
                    let image = images[index];
                    let url = image.common.file_url;
                    console.log(url);
                    message.channel.send(url);
                }
            )
            .catch(err => message.channel.send("Nothing turned up."));
        }
    }
}

module.exports.info = {
    name: "Booru"
}
AtoraSuunva commented 5 years ago

It's due to danbooru not supporting searching more than 2 tags at once, unless you are a gold+ member

Internally, booru uses order:random on sites that support it in order to return random results, so searching rating:questionable cat becomes rating:questionable cat order:random

You can either request I add api key support (I'm planning on adding that soon-ish) and pay $20/40 for gold/platinum, or don't use random if it's danbooru

There isn't much I can do my side sadly