chipmunkbot3/plugins/self_care.js

61 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-09-04 11:24:57 -04:00
const util = require('util')
2024-09-04 11:58:56 -04:00
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: '' }
2024-09-04 11:24:57 -04:00
function inject (bot) {
let permissionLevel, gamemode, commandSpyEnabled, vanished, godEnabled
bot.on('packet.login', packet => {
2024-09-04 11:24:57 -04:00
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')
2024-09-11 07:41:23 -04:00
else if (!commandSpyEnabled && bot.features.commandSpy) bot.chat.queue.unshift('/c on')
2024-09-04 11:24:57 -04:00
})
bot.on('packet.entity_status', packet => {
if (packet.entityStatus < 24 || packet.entityStatus > 28) return
permissionLevel = packet.entityStatus - 24
})
bot.on('system_chat', (message) => {
2024-09-11 07:41:23 -04:00
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
}
2024-09-04 11:24:57 -04:00
})
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 => {
2024-09-11 07:41:23 -04:00
gamemode = packet.gamemode
2024-09-04 11:24:57 -04:00
})
bot.on('packet.update_health', (packet) => {
if (packet.health <= 0) bot._client.write('client_command', { payload: 0 })
})
}
module.exports = inject