AtoraSuunva / booru

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

Empty posts for all sites but sb #48

Closed EmerickGrimm closed 3 years ago

EmerickGrimm commented 4 years ago

Code:

     module.exports = {
     name: 'fap',
    category: 'nsfw',
    description: 'Bot will post fap picture that you want',

    run: async (bot, message, args ) =>{
        const discord  = require('discord.js'); // bot stuff 

        const { RichEmbed } = require('discord.js'); 

        const Booru = require('booru')
        const { BooruError, sites } = require('booru')

        const site = 'rule34.xxx'
        const tags = [`${args[0]}`] //tags from msg's args

        await message.delete().catch (O_o=>{}); //delete msg that calls command

    if (message.channel.nsfw == true) // if  command called in nsfw channel than execute code  {

        const posts = await Booru.search(site, tags, {limit: 1, random: true});

        console.log(posts[0]);
        console.log(tags);

    /*
        console.log(`--------------------`)
        console.log(`Posting fap pic`)
        console.log(tags);
        console.log(posts[0].fileUrl);
        console.log(`--------------------`)

        const Embed = new discord.MessageEmbed()
                .setColor('#d91c0b')
                .setImage(`${posts[0].fileUrl}`)
                .setTimestamp()
                .setFooter(`Заказал: ${message.author.tag}`)

        message.channel.send(Embed);
    } else { 
        message.channel.send(':warning: You can't fap in public places')
    }
    */

Output:

undefined (empty posts[0] ?) [ 'ahri' ] (tag)

And same issue for all sites, but safebooru.

EmerickGrimm commented 4 years ago

Same code, but const site = 'safebooru' Output:

Post {
  data: {
    directory: '2636',
    hash: 'f7634abafa5afe90567686d60dfde60d',
    height: 766,
    id: 2745768,
    image: 'e6317bb8ee0ef2b0f00344c8438036e2a09964d8.png',
    change: 1547663471,
    owner: 'gelbooru',
    parent_id: 0,
    rating: 'safe',
    sample: false,
    sample_height: 0,
    sample_width: 0,
    score: null,
    tags: '1girl ahri animal_ears blonde_hair breasts choker cleavage fox_ears jewelry k/da_(league_of_legends) k/da_ahri league_of_legends long_hair makeup sasucchi95 solo thigh-highs whisker_markings yellow_eyes',
    width: 900
  },
  booru: Booru {
    domain: 'safebooru.org',
    site: Site {
      domain: 'safebooru.org',
      type: 'json',
      aliases: [Array],
      nsfw: false,
      api: [Object],
      paginate: 'pid',
      random: false,
      tagQuery: 'tags',
      insecure: false,
      defaultTags: []
    },
    credentials: null
  },
  fileUrl: 'https://safebooru.org/images/2636/e6317bb8ee0ef2b0f00344c8438036e2a09964d8.png',
  height: 766,
  width: 900,
  sampleUrl: null,
  sampleHeight: NaN,
  sampleWidth: NaN,
  previewUrl: null,
  previewHeight: NaN,
  previewWidth: NaN,
  id: '2745768',
  tags: [
    '1girl',
    'ahri',
    'animal_ears',
    'blonde_hair',
    'breasts',
    'choker',
    'cleavage',
    'fox_ears',
    'jewelry',
    'k/da_(league_of_legends)',
    'k/da_ahri',
    'league_of_legends',
    'long_hair',
    'makeup',
    'sasucchi95',
    'solo',
    'thigh-highs',
    'whisker_markings',
    'yellow_eyes'
  ],
  score: NaN,
  source: undefined,
  rating: 's',
  createdAt: Invalid Date
}
[ 'ahri' ]
AtoraSuunva commented 4 years ago

That's odd, I can't replicate that issue with this code:

const Booru = require('booru')

const site = 'rule34.xxx'
const tags = ['ahri']

;(async () => {
  const posts = await Booru.search(site, tags, { limit: 1, random: true })

  console.log('posts', posts[0])
  console.log('tags', tags)
})()

Nor if I try it with my own bot

Although looking at this line:

if (message.channel.nsfw == true) // if  command called in nsfw channel than execute code  {

That last { seems commented out, so that might be the issue (if you're testing the commands in a channel not marked nsfw)

EmerickGrimm commented 4 years ago

Tried your code (link to youtube vid me trying to run your code), same issue.