mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 18:54:55 -05:00
84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
/* eslint-disable prefer-rest-params */
|
|
|
|
function inject(bot, dcclient, config, rl) {
|
|
if (!config.console) return;
|
|
|
|
// readline > fix on console.log
|
|
const log = console.log;
|
|
console.log = function() {
|
|
rl.output.write('\x1b[2K\r');
|
|
log.apply(console, Array.prototype.slice.call(arguments));
|
|
rl._refreshLine();
|
|
};
|
|
const {MessageBuilder} = require('prismarine-chat')('1.18.2');
|
|
rl.on('line', function(line) {
|
|
try {
|
|
if (line.toLowerCase() === '' ||
|
|
line.toLowerCase().startsWith(' ')) return;
|
|
if (line.toLowerCase() === '.exit' || line.toLowerCase() === '.end') {
|
|
bot.emit('end', 'end command');
|
|
return;
|
|
}
|
|
if (line.toLowerCase().startsWith('.servereval ')) {
|
|
try {
|
|
bot.tellraw('@a', {
|
|
text: `${util.inspect(eval(`${line.substring(12)}`))}`,
|
|
color: 'green',
|
|
});
|
|
return;
|
|
} catch (err) {
|
|
bot.tellraw('@a', {text: `${util.inspect(err)}`, color: 'red'});
|
|
return;
|
|
}
|
|
}
|
|
if (line === '.clearconsolequeue') {
|
|
consoleQueue = [];
|
|
return;
|
|
}
|
|
if (line === '.messagelogging on') {
|
|
bot.consoleQueue = [];
|
|
bot.messageLogging = true;
|
|
return;
|
|
}
|
|
if (line === '.messagelogging off') {
|
|
bot.consoleQueue = [];
|
|
bot.messageLogging = false;
|
|
return;
|
|
}
|
|
if (line === '.kill') process.exit();
|
|
if (line.startsWith('.')) {
|
|
return bot.command_handler.run(
|
|
'Console',
|
|
'§a§lConsole§r',
|
|
'*' + line.substring(1),
|
|
'c0ns0le-uuid',
|
|
);
|
|
}
|
|
bot.tellraw('@a', [
|
|
{
|
|
text: '[',
|
|
color: 'dark_gray',
|
|
},
|
|
{
|
|
text: `${bot.username} Console`,
|
|
color: 'gray',
|
|
},
|
|
{
|
|
text: '] ',
|
|
color: 'dark_gray',
|
|
},
|
|
{
|
|
text: 'chayapak ',
|
|
color: 'green',
|
|
},
|
|
{
|
|
text: '\u203a ',
|
|
color: 'dark_gray',
|
|
},
|
|
MessageBuilder.fromString('&7' + line),
|
|
]);
|
|
} catch (e) {}
|
|
});
|
|
};
|
|
|
|
module.exports = {inject};
|