avamaxboobs
Version:
A package for randomly selecting images of various people's boobs. Intended to be used for discord bot commands.
34 lines (29 loc) • 1.89 kB
JavaScript
const fs = require('fs')
const path = require('path')
const moment = require('moment')
/**
* Get the time at which a list/backup file was last modified
* @param {string} type the type of file that you want to get the last modified time of (must be either 'backup' or 'list')
* @param {string} filename the name of the file that you want to get the last modified time of, INCLUDING the extension
* @returns {Promise<string>} the time at which the file was last modified, formatted using moment
*/
async function LastModified(type,filename){
if(!type || !filename) throw new Error('You must provide the type of file (list or backup) and filename that you want to get the last modified time of!')
if(typeof type!='string' || typeof filename!='string') throw new Error('Both type and filename must be strings')
if(type!='list' && type!='backup') throw new Error('type must be either \'list\' or \'backup\'')
if(type==='list'){
if(!fs.existsSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${filename}`))) throw new Error(`There is no list named ${filename}! Use the CreateCustomList() function to create one!`)
const modifiedat = moment(fs.statSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${filename}`)).mtimeMs).format('LLLL')
return modifiedat;
}
if(type==='backup'){
const dir = path.join(`${os.homedir()}`,'avamaxboobs-backups')
if(!fs.existsSync(dir)) throw new Error('You don\'t have any backups. Use the CreateBackup() function to create one!')
if(!fs.existsSync(path.join(dir,filename))) throw new Error(`You don\'t have a backup for ${filename}! use the CreateBackup() function to create one!`)
const modifiedat = moment(fs.statSync(path.join(`${dir}`,`${filename}`)).mtimeMs).format('LLLL')
return modifiedat;
}
}
module.exports={
LastModified
}