UNPKG

avamaxboobs

Version:

A package for randomly selecting images of various people's boobs. Intended to be used for discord bot commands.

31 lines (25 loc) 1.17 kB
const fs =require('fs') const path = require('path') /** * Create a backup of a list. Backups are stored in (your project's route folder)/avamaxboobs-backups * @param {string} list the list to create a backup of * @example CreateBackup('avamaxboobs') */ async function CreateBackup(list){ if(typeof list !='string') throw new Error('List must be a string'); const lists = fs.readdirSync(path.join(__dirname.slice(0,__dirname.length-15),'lists')); if(!lists.includes(`${list}.json`)) throw new Error(`Invalid list. List must be one of the following: ${lists.map(file=>file.slice(0,file.length-5)).join(', ')}`) const dir = path.join(path.join(__dirname,'../../../../'),'avamaxboobs-backups'); if(!fs.existsSync(dir)){ fs.mkdirSync(dir); } const file = fs.readFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`)); const json = JSON.parse(file); const jsonstring = JSON.stringify(json).replaceAll(',',',\n').replaceAll('}','\n}'); fs.writeFileSync(path.join(dir,`${list}.json`),jsonstring,'utf-8',(err)=>{ if(err) throw err; }); } module.exports={ CreateBackup }