34 lines
882 B
JavaScript
34 lines
882 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 bot (bot) { bot.blacklist = blacklist }
|
|
|
|
function client (bot, client) {
|
|
client.on('player_info', (packet) => {
|
|
if (packet.action === 0) {
|
|
packet.data.forEach((player) => {
|
|
blacklist.forEach(([pattern, flags]) => {
|
|
if (new RegExp(pattern, flags).test(player.name)) { bot.exploits.uuidBan(player.UUID) }
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
module.exports = { bot, client }
|