chipmunkbot3/plugins/self_care.js

60 lines
2.2 KiB
JavaScript

const util = require('util')
const COMMANDSPY_ENABLED_MESSAGE = { text: 'Successfully enabled CommandSpy' }
const COMMANDSPY_DISABLED_MESSAGE = { text: 'Successfully disabled CommandSpy' }
const COMMANDSPY_ENABLED_MESSAGE_2 = { extra: [ 'Successfully ', 'enabled', ' CommandSpy' ], text: '' }
const COMMANDSPY_DISABLED_MESSAGE_2 = { extra: [ 'Successfully ', 'disabled', ' CommandSpy' ], text: '' }
function inject (bot) {
let permissionLevel, gamemode, commandSpyEnabled, vanished, godEnabled
bot.on('packet.login', packet => {
permissionLevel = 0
gamemode = packet.gameMode
commandSpyEnabled = false
vanished = false
godEnabled = false
})
bot.on('chat_queue_tick', () => {
if (permissionLevel === 0) bot.chat.queue.unshift('/op @s[type=player]')
else if (gamemode !== 1) bot.chat.queue.unshift('/gamemode creative')
else if (!commandSpyEnabled && bot.features.commandSpy) bot.chat.queue.unshift('/c on')
})
bot.on('packet.entity_status', packet => {
if (packet.entityStatus < 24 || packet.entityStatus > 28) return
permissionLevel = packet.entityStatus - 24
})
bot.on('system_chat', (message) => {
if (bot.features.commandSpy) {
if (message === COMMANDSPY_ENABLED_MESSAGE.text || util.isDeepStrictEqual(message, COMMANDSPY_ENABLED_MESSAGE) || util.isDeepStrictEqual(message, COMMANDSPY_ENABLED_MESSAGE_2)) commandSpyEnabled = true
else if (message === COMMANDSPY_DISABLED_MESSAGE.text || util.isDeepStrictEqual(message, COMMANDSPY_DISABLED_MESSAGE) || util.isDeepStrictEqual(message, COMMANDSPY_DISABLED_MESSAGE_2)) commandSpyEnabled = false
}
})
bot.on('player_added', (player) => {
if (player.uuid === bot.uuid && player.username !== bot.username) bot.core.run(`essentials:sudo ${bot.uuid} username ${bot.username}`)
})
bot.on('packet.game_state_change', (packet) => {
switch (packet.reason) {
case 3:
gamemode = packet.gameMode
break
case 4:
bot._client.write('client_command', { payload: 0 })
}
})
bot.on('packet.respawn', packet => {
gamemode = packet.gamemode
})
bot.on('packet.update_health', (packet) => {
if (packet.health <= 0) bot._client.write('client_command', { payload: 0 })
})
}
module.exports = inject