avamaxboobs
Version:
A package for randomly selecting images of various people's boobs. Intended to be used for discord bot commands.
38 lines (31 loc) • 1.4 kB
JavaScript
const fs = require('fs')
const path = require('path')
/**
* Checks the specified list for the specified item. Will return true if the item is found, and false otherwise.
* @param {string} list the list to check
* @param {string} item the item to check for. Note that this IS case sensitive
* @returns {Boolean} whether or not the specified list contains the specified item
*/
async function HasItem(list,item){
if(!list||!item) throw new Error('You must provide the list to search and the item to search for.');
if(typeof list !='string' || typeof item!='string') throw new Error('List and item must both be strings.')
if(list==='boobsvideos') throw new Error('This function does not work with the boobsvideos list.')
const dir = path.join(__dirname.slice(0,__dirname.length-15),'lists')
const listfolder = fs.readdirSync(dir)
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(', ')}`)
}
let found = false;
const file = fs.readFileSync(path.join(dir,`${list}.json`))
const keys = Object.keys(JSON.parse(file.toString()))
const val = JSON.parse(file.toString())[keys]
val.forEach(cum=>{
if(cum.includes(item)){
found = true;
}
});
return found;
}
module.exports={
HasItem
}