chipmunkbot3/plugins/blacklist.js

35 lines
882 B
JavaScript
Raw Normal View History

2024-02-11 21:23:41 -05:00
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 }