upgrade console layout + usage upgrade

it took real shit ages to do this shit
This commit is contained in:
ChomeNS 2022-11-13 13:52:37 +07:00
parent 01475e3085
commit 441abf7264
5 changed files with 59 additions and 30 deletions

View file

@ -53,10 +53,22 @@ module.exports = {
if (command.alias.toString() !== '') { if (command.alias.toString() !== '') {
alias = command.alias.join(', '); alias = command.alias.join(', ');
} }
const usage = [];
if (typeof command.usage === 'string') {
usage.push({text: `${prefix}${command.name} `, color: 'gold'});
usage.push({text: command.usage, color: 'aqua'});
} else {
command.usage.forEach((value) => {
usage.push({text: `${prefix}${command.name} `, color: 'gold'});
usage.push({text: `${value}\n`, color: 'aqua'});
});
}
bot.tellraw('@a', [{text: prefix + command.name, color: 'gold'}, {text: ` (${alias})`, color: 'white'}, {text: ' - ', color: 'gray'}, {text: command.description, color: 'gray'}]); bot.tellraw('@a', [{text: prefix + command.name, color: 'gold'}, {text: ` (${alias})`, color: 'white'}, {text: ' - ', color: 'gray'}, {text: command.description, color: 'gray'}]);
bot.tellraw('@a', [{text: 'Trust level: ', color: 'green'}, {text: command.trusted, color: 'yellow'}]); bot.tellraw('@a', [{text: 'Trust level: ', color: 'green'}, {text: command.trusted, color: 'yellow'}]);
bot.tellraw('@a', [{text: 'Supported on Discord: ', color: 'green'}, {text: discordSupported, color: 'gold'}]); bot.tellraw('@a', [{text: 'Supported on Discord: ', color: 'green'}, {text: discordSupported, color: 'gold'}]);
bot.tellraw('@a', [{text: prefix + command.name, color: 'gold'}, {text: ' ' + command.usage, color: 'aqua'}]); bot.tellraw('@a', usage);
} }
if (command.name === args[0]) run(); if (command.name === args[0]) run();

View file

@ -23,12 +23,12 @@ const {VM} = require('vm2');
const randomstring = require('randomstring'); const randomstring = require('randomstring');
const mineflayer = require('mineflayer'); const mineflayer = require('mineflayer');
// readline > fix on console.log // readline > fix on console.log
const log = console.log; // const log = console.log;
console.log = function() { // console.log = function() {
rl.output.write('\x1b[2K\r'); // rl.output.write('\x1b[2K\r');
log.apply(console, Array.prototype.slice.call(arguments)); // log.apply(console, Array.prototype.slice.call(arguments));
rl._refreshLine(); // rl._refreshLine();
}; // };
// Load discord.js // Load discord.js
const { const {
@ -76,7 +76,7 @@ async function botThings() {
/** /**
* Main bot function * Main bot function
*/ */
function main() { async function main() {
const channel = dcclient.channels.cache.get(config.discord.servers[process.argv[2]]); const channel = dcclient.channels.cache.get(config.discord.servers[process.argv[2]]);
module.exports = bot; module.exports = bot;
@ -85,7 +85,7 @@ function main() {
bot.getplayerusername = {}; bot.getplayerusername = {};
bot.once('end', (reason, event) => { bot.once('end', (reason, event) => {
console.log( bot.console.info(
`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`, `Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`,
); );
channel.send(`Disconnected: \`${util.inspect(reason)}\``); channel.send(`Disconnected: \`${util.inspect(reason)}\``);
@ -101,7 +101,7 @@ function main() {
) timeout = 1000 * 7; ) timeout = 1000 * 7;
} }
} catch (e) { } catch (e) {
console.log(e); bot.console.error(e);
} }
setTimeout(() => { setTimeout(() => {
@ -111,15 +111,18 @@ function main() {
}, timeout); }, timeout);
}); });
console.log(`Connecting to: ${bot.options.host}:${bot.options.port}...`); await sleep(1000);
bot.console.info(`Connecting to: ${bot.options.host}:${bot.options.port}...`);
channel.send(`Connecting to: \`${bot.options.host}:${bot.options.port}\`...`); channel.send(`Connecting to: \`${bot.options.host}:${bot.options.port}\`...`);
console.log(bot._client);
bot._client.on('login', async function(data) { bot._client.on('login', async function(data) {
bot.entityId = data.entityId; bot.entityId = data.entityId;
bot.uuid = bot._client.uuid; bot.uuid = bot._client.uuid;
bot.username = bot._client.username; bot.username = bot._client.username;
chatMessage = require('prismarine-chat')(bot.version); chatMessage = require('prismarine-chat')(bot.version);
const mcData = require('minecraft-data')(bot.version); const mcData = require('minecraft-data')(bot.version);
console.log( bot.console.info(
`Successfully logged in to: ${bot.options.host}:${bot.options.port}`, `Successfully logged in to: ${bot.options.host}:${bot.options.port}`,
); );
channel.send( channel.send(
@ -208,7 +211,7 @@ function main() {
bot._client.on('error', function() {}); bot._client.on('error', function() {});
process.on('uncaughtException', (error) => { process.on('uncaughtException', (error) => {
console.log('uncaught ' + util.inspect(error)); console.error('uncaught ' + util.inspect(error));
channel.send('uncaught ```\n' + util.inspect(error) + '\n```'); channel.send('uncaught ```\n' + util.inspect(error) + '\n```');
bot.emit('end', 'uncaughtException', 'process: uncaughtException'); bot.emit('end', 'uncaughtException', 'process: uncaughtException');
}); });

View file

@ -17,7 +17,7 @@ function inject(bot) {
bot.write('chat', {message: bot.chatQueue[0].substring(0, 256)}); bot.write('chat', {message: bot.chatQueue[0].substring(0, 256)});
bot.chatQueue.shift(); bot.chatQueue.shift();
} catch (e) { } catch (e) {
console.log(e.message); bot.console.error(e);
} }
} }
} catch (e) { } catch (e) {

View file

@ -1,20 +1,35 @@
/* eslint-disable max-len */
/* eslint-disable prefer-rest-params */ /* eslint-disable prefer-rest-params */
const moment = require('moment-timezone');
function inject(bot, dcclient, config, rl) { function inject(bot, dcclient, config, rl) {
if (!config.console) return; if (!config.console) return;
const chatMessage = require('prismarine-chat')(bot.version);
function prefix(prefix, _message) {
const message = `[${moment().format('HH:mm:ss')} ${prefix}§r] [${bot.options.host}] ${_message}`;
const component = chatMessage.MessageBuilder.fromString(message).toJSON();
return chatMessage.fromNotch(component).toAnsi();
}
bot.console = {};
bot.console.log = function(message) {
console.log(prefix('&6LOG', message));
};
bot.console.info = function(message) {
console.log(prefix('&aINFO', message));
};
bot.console.error = function(message) {
console.log(prefix('&cERROR', message));
};
bot.consoleQueue = []; bot.consoleQueue = [];
const consoleQueueInterval = setInterval(function() { const consoleQueueInterval = setInterval(function() {
if (!bot.messageLogging) return; if (!bot.messageLogging) return;
if (bot.consoleQueue.length > 50) bot.consoleQueue = []; if (bot.consoleQueue.length > 50) bot.consoleQueue = [];
if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') { if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') {
console.log( bot.console.log(bot.consoleQueue[0].substring(0, 10000));
'\u001b[48:5:208m' +
bot.options.host +
'\u001b[0m' +
': ' +
bot.consoleQueue[0].substring(0, 10000),
);
bot.consoleQueue.shift(); bot.consoleQueue.shift();
} }
}, 100); }, 100);
@ -35,7 +50,6 @@ function inject(bot, dcclient, config, rl) {
log.apply(console, Array.prototype.slice.call(arguments)); log.apply(console, Array.prototype.slice.call(arguments));
rl._refreshLine(); rl._refreshLine();
}; };
const {MessageBuilder} = require('prismarine-chat')('1.18.2');
rl.on('line', function(line) { rl.on('line', function(line) {
try { try {
if (line.toLowerCase() === '' || if (line.toLowerCase() === '' ||
@ -73,10 +87,10 @@ function inject(bot, dcclient, config, rl) {
if (line === '.kill') process.exit(); if (line === '.kill') process.exit();
if (line.startsWith('.')) { if (line.startsWith('.')) {
return bot.command_handler.run( return bot.command_handler.run(
'Console', bot.username,
'§a§lConsole§r', bot.username,
'*' + line.substring(1), '*' + line.substring(1),
'c0ns0le-uuid', bot.uuid,
); );
} }
bot.tellraw('@a', [ bot.tellraw('@a', [
@ -100,9 +114,11 @@ function inject(bot, dcclient, config, rl) {
text: '\u203a ', text: '\u203a ',
color: 'dark_gray', color: 'dark_gray',
}, },
MessageBuilder.fromString('&7' + line), chatMessage.MessageBuilder.fromString('&7' + line),
]); ]);
} catch (e) {} } catch (e) {
bot.console.error(e);
}
}); });
}; };

View file

@ -90,9 +90,7 @@ function inject(bot, dcclient, config) {
}); });
fillCore(); fillCore();
} catch (e) { } catch (e) {}
return;
}
}, },
// fillCore(useCore) { // fillCore(useCore) {
// const fillCommand = `/minecraft:fill ${core.start.x} ${core.start.y} ${core.start.z} ${core.end.x} ${core.end.y} ${core.end.z} command_block{CustomName:'{"text":"ChomeNS Bot Core","color":"yellow"}'}`; // const fillCommand = `/minecraft:fill ${core.start.x} ${core.start.y} ${core.start.z} ${core.end.x} ${core.end.y} ${core.end.z} command_block{CustomName:'{"text":"ChomeNS Bot Core","color":"yellow"}'}`;