chipmunkbot-archive/util/persistent-data.js
2022-11-13 01:32:35 +00:00

24 lines
492 B
JavaScript

const fs = require('fs/promises')
const path = require('path')
const nbt = require('prismarine-nbt')
async function load (filepath) {
let parsed
let type
try {
{ parsed, type } = await nbt.parse(await fs.readFile(filepath))
} catch (err) {
parsed = nbt.comp({})
type = 'big'
}
async function save () {
await fs.writeFile(filepath, nbt.writeUncompressed(parsed, type))
}
setInterval(save, 5 * 60 * 1000)
return parsed
}
module.exports = load('data.nbt')