31 lines
769 B
JavaScript
31 lines
769 B
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const filepath = path.resolve('persistent', 'blacklist.json')
|
|
|
|
// load the blacklist
|
|
let blacklist = []
|
|
try {
|
|
blacklist = require(filepath)
|
|
} catch (e) {
|
|
console.log('An error occured while loading the blacklist.')
|
|
}
|
|
|
|
// save it every 5 minutes
|
|
setInterval(() => {
|
|
fs.writeFileSync(filepath, JSON.stringify(blacklist, null, 2))
|
|
}, 5 * 6000)
|
|
|
|
// expose the blacklist and make the bot uuid ban blacklisted players
|
|
function inject (bot) {
|
|
bot.blacklist = blacklist
|
|
|
|
bot.on('player_added', player => {
|
|
for (const [pattern, flags] of blacklist) {
|
|
const regex = new RegExp(pattern, flags)
|
|
if (regex.test(player.username)) bot.exploits.uuidBan(player.uuid)
|
|
}
|
|
})
|
|
}
|
|
|
|
module.exports = inject
|