avamaxboobs
Version:
A package for randomly selecting images of various people's boobs. Intended to be used for discord bot commands.
25 lines (21 loc) • 1.05 kB
JavaScript
const fs =require('fs');
const path = require('path')
/**
* Get a random image from a list
* @param {string} list the list to get a random image from
* @returns {Promise<string>} random image from the provided list
* @example RandomImage('boobs') //returns a random image from the list 'boobs', if it exists
*/
async function RandomImage(list){
if(typeof list!='string') throw new Error('List must be a string');
const listfolder = fs.readdirSync(path.join(__dirname.slice(0,__dirname.length-21),'lists'));
if(!listfolder.includes(`${list}.json`)) throw new Error(`Invalid list. List must be one of the following: ${listfolder.map(file=>file.slice(0,file.length-5)).join(', ')}`)
const listfile = fs.readFileSync(path.join(__dirname.slice(0,__dirname.length-21),'lists',`${list}.json`))
const keys = Object.keys(JSON.parse(listfile.toString()))
const val = JSON.parse(listfile.toString())[keys]
const image = val[Math.floor(Math.random()*val.length)];
return image;
}
module.exports={
RandomImage
}