chomens-bot-js/plugins/proxy/self_care.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-11-16 20:46:04 -05:00
/* eslint-disable max-len */
/* eslint-disable require-jsdoc */
function inject(bot, client, targetClient, config) {
let cspy = false;
let op = true;
let gameMode = 1;
targetClient.on('parsed_chat', (data) => {
if (data.toString() === 'Successfully enabled CommandSpy' || data.toString() === ' Enabled your command spy.' || data.toString() === ' Your command spy is already enabled.') cspy = true;
if (data.toString() === 'Successfully disabled CommandSpy' || data.toString() === ' Disabled your command spy.') cspy = false;
});
targetClient.on('entity_status', (data) => {
if (data.entityId !== targetClient.entityId) return;
switch (data.entityStatus) {
case 24:
op = false;
break;
case 28:
op = true;
break;
}
});
targetClient.on('game_state_change', (data) => {
if (data.reason !== 3) return;
gameMode = data.gameMode;
});
targetClient.once('login', (data) => {
gameMode = data.gameMode;
});
const interval = setInterval(() => {
if (bot.options.host !== '0.tcp.ap.ngrok.io') {
if (!op && config.self_care.op) targetClient.chat('/minecraft:op @s[type=player]');
if (!cspy && config.self_care.cspy) targetClient.chat('/commandspy:commandspy on');
}
if (gameMode !== 1 && config.self_care.gamemode) targetClient.chat('/minecraft:gamemode creative @s[type=player]');
}, config.self_care_check_interval);
bot.once('end', () => {
clearInterval(interval);
});
};
module.exports = {inject};