avamaxboobs
Version:
A package for randomly selecting images of various people's boobs. Intended to be used for discord bot commands.
104 lines (89 loc) • 5.63 kB
JavaScript
const fs = require('fs');
const path = require('path');
/**
* Add an item or several items to a list
*
* IMPORTANT:
*
* Note that ANY items you add to a list yourself will be removed when installing a new version of the package, therefore I HIGHLY recommend you backup your lists before doing so.
* @param {string} list The list to add the item(s) to
* @param {string|ArrayOfStrings|object} item A string or array of strings to add to the list, unless you are adding to the boobsvideos list, in which case it should be an object containing a title, thumbnail and url property
* @example addToList('avamaxboobs','https://media.discordapp.net/attachments/1173368308297367592/1316198458604126299/IMG_3310.png?ex=675a2cd6&is=6758db56&hm=f39fc3980e9dee75af5749a5010406e6d6c65d96bddd9993689f2bcc8bcb0b45&')
* @example addToList('boobsvideos',{"title":"Amanda Love trying on bras","thumbnail":"https://gcore-pic.xvideos-cdn.com/videos/thumbs169ll/c2/08/15/c2081512b221d50ac64711b9b0a9b952/c2081512b221d50ac64711b9b0a9b952.14.jpg","url":"https://www.xvideos.com/video.kdutauv48ab/amanda_love_trying_on_bras"})
*/
async function addToList(list,item){
if(!list || !item) throw new Error('You must provide a list to add the item to AND an item');
if(typeof list !='string') throw new Error('List must be a string')
if(list!='boobsvideos'){
if(typeof item !='string' && !item.length) throw new Error('Item must be either a string or array of strings');
if(typeof item ==='string'){
if(!item.startsWith('http://') && !item.startsWith('https://')) throw new Error('Item must be a direct link to an image')
}
}else{
if (typeof item !='object' || !item.title ||!item.thumbnail || !item.url) throw new Error('Items added to boobsvideos list must be objects containing a title, thumbnail and url property.')
}
if(typeof item !='string'){
if(item.length){
let semen = 0;
let balls = 0;
item.forEach(balls=>{
if(typeof balls !='string'){
semen = semen+1;
}
})
if(semen!=0){
throw new Error('Item must be either a string or array of strings')
}
item.forEach(sex=>{
if(!sex.startsWith('http://') && !sex.startsWith('https://'))
balls = balls+1;
});
if(balls!=0){
throw new Error('Item must be a direct link to an image')
}
}else{
if(!item.title || !item.thumbnail || !item.url) throw new Error('Items added to boobsvideo list must be objects containing a title, thumbnail and url property.')
if(typeof item.title!='string' || typeof item.thumbnail!='string' || typeof item.url!='string') throw new Error('Title, thumbnail and url properties must all be strings.')
if(!item.thumbnail.startsWith('http://') && !item.thumbnail.startsWith('https://')) throw new Error('Thumbnail must be a direct link to an image')
if(!item.thumbnail.endsWith('.png') && !item.thumbnail.endsWith('.jpg')) throw new Error('Thumbnail must be a direct link to an image')
if(!item.url.startsWith('http://') && !item.url.startsWith('https://')) throw new Error('Url must be a link.')
}
}
const folder = fs.readdirSync(path.join(__dirname.slice(0,__dirname.length-15),'lists'));
if(!folder.includes(`${list}.json`)) throw new Error(`Invalid list. List must be one of the following: ${folder.map(file=>file.slice(0,file.length-5)).join(', ')}`)
if(typeof item==='string'){
const listfile = fs.readFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`))
const keys = Object.keys(JSON.parse(listfile.toString()))
const val = JSON.parse(listfile.toString())[keys]
val.push(item)
const string = `{\n"${list}":[${val.map(val=>`"${val}"`).join(',\n')}]\n}`
fs.writeFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`),string,'utf-8',(err=>{
if(err) throw err;
}));
}else{
if(item[0]){
const listfile = fs.readFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`))
const keys = Object.keys(JSON.parse(listfile.toString()))
const val = JSON.parse(listfile.toString())[keys]
item.forEach(item=>{
val.push(item)
})
const string = `{\n"${list}":[${val.map(val=>`"${val}"`).join(',\n')}]\n}`
fs.writeFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`),string,'utf-8',(err=>{
if(err) throw err;
}));
}else{
const listfile = fs.readFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`))
const keys = Object.keys(JSON.parse(listfile.toString()))
const val = JSON.parse(listfile.toString())[keys]
val.push(item)
const string = `{\n"${list}":[${val.map(val=>`{"title":"${val.title}",\n"thumbnail":"${val.thumbnail}",\n"url":"${val.url}"\n}`).join(',\n')}]\n}`
fs.writeFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`),string,'utf-8',(err=>{
if(err) throw err;
}));
}
}
}
module.exports={
addToList
}