29 lines
664 B
JavaScript
29 lines
664 B
JavaScript
|
const fs = require('fs')
|
||
|
const path = require('path')
|
||
|
|
||
|
const filepath = path.resolve('persistent', 'mail.json')
|
||
|
|
||
|
// load the blacklist
|
||
|
let mail = {}
|
||
|
try {
|
||
|
mail = require(filepath)
|
||
|
} catch (e) {
|
||
|
console.log('An error occured while loading the mail.')
|
||
|
}
|
||
|
|
||
|
// save it every 5 minutes
|
||
|
setInterval(() => {
|
||
|
fs.writeFileSync(filepath, JSON.stringify(mail, null, 2))
|
||
|
}, 5 * 6000)
|
||
|
|
||
|
// make the bot uuid ban blacklisted players
|
||
|
function inject (bot) {
|
||
|
bot.mail = mail
|
||
|
bot.sendMail = (sender, reciever, message) => {
|
||
|
if (!mail[reciever]) mail[reciever] = []
|
||
|
mail[reciever].push({ sender: sender, message, host: bot.host })
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports.bot = inject
|