mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-27 09:35:35 -05:00
real console update!1!1
This commit is contained in:
parent
a507fe019e
commit
a80298567f
4 changed files with 96 additions and 82 deletions
|
@ -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',
|
||||
'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,
|
||||
'core': {
|
||||
'layers': 3,
|
||||
|
|
89
index.js
89
index.js
|
@ -87,12 +87,11 @@ function botThings() {
|
|||
};
|
||||
bot.visibility = false;
|
||||
bot.getplayerusername = {};
|
||||
if (!bot.messageLogging) bot.messageLogging = true;
|
||||
|
||||
loadPlugins(bot, dcclient, config);
|
||||
loadPlugins(bot, dcclient, config, rl);
|
||||
}
|
||||
|
||||
let messageloggingEnabled = true;
|
||||
|
||||
/**
|
||||
* Main bot function
|
||||
*/
|
||||
|
@ -122,7 +121,7 @@ function main() {
|
|||
};
|
||||
|
||||
dcmsg.queue = '';
|
||||
consoleQueue = [];
|
||||
bot.consoleQueue = [];
|
||||
|
||||
bot.playersAddedPlayers = {};
|
||||
bot.getplayerusername = {};
|
||||
|
@ -146,17 +145,17 @@ function main() {
|
|||
}, 1000);
|
||||
|
||||
consoleQueueInterval = setInterval(function() {
|
||||
if (!messageloggingEnabled) return;
|
||||
if (consoleQueue.length > 50) consoleQueue = [];
|
||||
if (consoleQueue[0] || consoleQueue[0] === '') {
|
||||
if (!bot.messageLogging) return;
|
||||
if (bot.consoleQueue.length > 50) bot.consoleQueue = [];
|
||||
if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') {
|
||||
console.log(
|
||||
'\u001b[48:5:208m' +
|
||||
bot.options.host +
|
||||
'\u001b[0m' +
|
||||
': ' +
|
||||
consoleQueue[0].substring(0, 10000),
|
||||
bot.consoleQueue[0].substring(0, 10000),
|
||||
);
|
||||
consoleQueue.shift();
|
||||
bot.consoleQueue.shift();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
|
@ -289,7 +288,7 @@ function main() {
|
|||
.replaceAll('http', 'http\u200b')
|
||||
.replaceAll('\u001b[9', '\u001b[3');
|
||||
|
||||
consoleQueue.push(message.toAnsi());
|
||||
bot.consoleQueue.push(message.toAnsi());
|
||||
|
||||
if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return;
|
||||
dcmsg.queue += '\n' + discordMsg;
|
||||
|
@ -367,76 +366,6 @@ dcclient.on('ready', async () => {
|
|||
bot.ownerhashchannel = dcclient.channels.cache.get(ownerhashchannel);
|
||||
bot.channelId = channel.id;
|
||||
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
|
||||
|
|
84
plugins/console.js
Normal file
84
plugins/console.js
Normal 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};
|
|
@ -2,13 +2,13 @@ const fs = require('fs/promises');
|
|||
const util = require('util');
|
||||
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'));
|
||||
|
||||
plugins.forEach((plugin) => {
|
||||
try {
|
||||
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
|
||||
plug.inject(bot, dcclient, config);
|
||||
plug.inject(bot, dcclient, config, rl);
|
||||
} catch (e) {
|
||||
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
|
||||
console.log(util.inspect(e));
|
||||
|
|
Loading…
Reference in a new issue