avamaxboobs
Version:
A package for randomly selecting images of various people's boobs. Intended to be used for discord bot commands.
34 lines (25 loc) • 1.41 kB
JavaScript
const fs = require('fs')
const path = require('path')
/**
* Load a backup of a list.
* @param {string} list the list to load a backup of
* @example LoadBackup('avamaxboobs')
*/
async function LoadBackup(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)) throw new Error('You don\'t have any backups to load! Use the CreateBackup() function to create one!')
const backupfolder = fs.readdirSync(dir);
if(!backupfolder.includes(`${list}.json`)) throw new Error(`You don\'t have a backup for ${list}! Use the CreateBackup() function to create one!`);
const backupfile = fs.readFileSync(path.join(`${dir}`,`${list}.json`));
const json = JSON.parse(backupfile);
const jsonstring = JSON.stringify(json).replaceAll(',',',\n').replaceAll('}','\n}');
fs.writeFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`),jsonstring,'utf-8',(err)=>{
if(err) throw err;
});
}
module.exports={
LoadBackup
}