real console update!1!1

This commit is contained in:
ChomeNS 2022-11-09 19:04:14 +07:00
parent a507fe019e
commit a80298567f
4 changed files with 96 additions and 82 deletions

View file

@ -11,6 +11,7 @@ module.exports = {
'normalKey': '<27>iB_D<5F><44><EFBFBD>k<EFBFBD><6B>j8H<38>{?[/ڭ<>f<EFBFBD><>^-=<3D>Ț<EFBFBD><C89A>v]<5D><>g><3E><>=c', 'normalKey': '<27>iB_D<5F><44><EFBFBD>k<EFBFBD><6B>j8H<38>{?[/ڭ<>f<EFBFBD><>^-=<3D>Ț<EFBFBD><C89A>v]<5D><>g><3E><>=c',
'ownerHashKey': 'b)R<><52>nF<6E>CW<43><57><EFBFBD>#<23>\\[<5B>S*8"t^eia<69>Z<EFBFBD><5A>k<EFBFBD><6B><EFBFBD><EFBFBD>K1<4B>8zȢ<7A>', 'ownerHashKey': 'b)R<><52>nF<6E>CW<43><57><EFBFBD>#<23>\\[<5B>S*8"t^eia<69>Z<EFBFBD><5A>k<EFBFBD><6B><EFBFBD><EFBFBD>K1<4B>8zȢ<7A>',
}, },
'console': true,
'useChat': false, 'useChat': false,
'core': { 'core': {
'layers': 3, 'layers': 3,

View file

@ -87,12 +87,11 @@ function botThings() {
}; };
bot.visibility = false; bot.visibility = false;
bot.getplayerusername = {}; bot.getplayerusername = {};
if (!bot.messageLogging) bot.messageLogging = true;
loadPlugins(bot, dcclient, config); loadPlugins(bot, dcclient, config, rl);
} }
let messageloggingEnabled = true;
/** /**
* Main bot function * Main bot function
*/ */
@ -122,7 +121,7 @@ function main() {
}; };
dcmsg.queue = ''; dcmsg.queue = '';
consoleQueue = []; bot.consoleQueue = [];
bot.playersAddedPlayers = {}; bot.playersAddedPlayers = {};
bot.getplayerusername = {}; bot.getplayerusername = {};
@ -146,17 +145,17 @@ function main() {
}, 1000); }, 1000);
consoleQueueInterval = setInterval(function() { consoleQueueInterval = setInterval(function() {
if (!messageloggingEnabled) return; if (!bot.messageLogging) return;
if (consoleQueue.length > 50) consoleQueue = []; if (bot.consoleQueue.length > 50) bot.consoleQueue = [];
if (consoleQueue[0] || consoleQueue[0] === '') { if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') {
console.log( console.log(
'\u001b[48:5:208m' + '\u001b[48:5:208m' +
bot.options.host + bot.options.host +
'\u001b[0m' + '\u001b[0m' +
': ' + ': ' +
consoleQueue[0].substring(0, 10000), bot.consoleQueue[0].substring(0, 10000),
); );
consoleQueue.shift(); bot.consoleQueue.shift();
} }
}, 100); }, 100);
@ -289,7 +288,7 @@ function main() {
.replaceAll('http', 'http\u200b') .replaceAll('http', 'http\u200b')
.replaceAll('\u001b[9', '\u001b[3'); .replaceAll('\u001b[9', '\u001b[3');
consoleQueue.push(message.toAnsi()); bot.consoleQueue.push(message.toAnsi());
if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return; if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return;
dcmsg.queue += '\n' + discordMsg; dcmsg.queue += '\n' + discordMsg;
@ -367,76 +366,6 @@ dcclient.on('ready', async () => {
bot.ownerhashchannel = dcclient.channels.cache.get(ownerhashchannel); bot.ownerhashchannel = dcclient.channels.cache.get(ownerhashchannel);
bot.channelId = channel.id; bot.channelId = channel.id;
attachmentlink = ''; attachmentlink = '';
// Console COMMANDS
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') {
messageloggingEnabled = true;
return;
}
if (line === '.messagelogging off') {
messageloggingEnabled = 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',
},
chatMessage.MessageBuilder.fromString('&7' + line),
]);
} catch (e) {
console.log(e);
}
});
}); });
// Redirect Discord messages to in-game chat // Redirect Discord messages to in-game chat

84
plugins/console.js Normal file
View file

@ -0,0 +1,84 @@
/* 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};

View file

@ -2,13 +2,13 @@ const fs = require('fs/promises');
const util = require('util'); const util = require('util');
const path = require('path'); const path = require('path');
async function loadPlugins(bot, dcclient, config) { async function loadPlugins(bot, dcclient, config, rl) {
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins')); const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
plugins.forEach((plugin) => { plugins.forEach((plugin) => {
try { try {
const plug = require(path.join(__dirname, '..', 'plugins', plugin)); const plug = require(path.join(__dirname, '..', 'plugins', plugin));
plug.inject(bot, dcclient, config); plug.inject(bot, dcclient, config, rl);
} catch (e) { } catch (e) {
console.log(`Plugin ${plugin} is having exception loading the plugin:`); console.log(`Plugin ${plugin} is having exception loading the plugin:`);
console.log(util.inspect(e)); console.log(util.inspect(e));