mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-23 15:47:57 -05:00
among us console fix + cloop discord fix
This commit is contained in:
parent
7cacc880e0
commit
a30eb19759
6 changed files with 111 additions and 118 deletions
5
bot.js
5
bot.js
|
@ -8,9 +8,6 @@ const generateEaglerUsername = require('./util/generateEaglerUsername');
|
|||
const {EventEmitter} = require('events');
|
||||
const {loadPlugins} = require('./util/loadPlugins');
|
||||
const uuid = require('uuid-by-string');
|
||||
const readline = require('node:readline');
|
||||
const {stdin: input, stdout: output} = require('node:process');
|
||||
const rl = readline.createInterface({input, output});
|
||||
const moment = require('moment-timezone');
|
||||
const cowsay = require('cowsay2');
|
||||
const cows = require('cowsay2/cows');
|
||||
|
@ -57,7 +54,7 @@ async function createBot(server, config, getBots, dcclient) {
|
|||
|
||||
await sleep(200);
|
||||
|
||||
await loadPlugins(bot, dcclient, config, rl);
|
||||
await loadPlugins(bot, dcclient, config);
|
||||
|
||||
const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host]);
|
||||
|
||||
|
|
|
@ -104,14 +104,14 @@ module.exports = {
|
|||
} else if (args[0] === 'list') {
|
||||
list(bot, true, channeldc);
|
||||
} else if (args[0] === 'remove') {
|
||||
remove(args[1]);
|
||||
remove(args[1], bot);
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Cloop')
|
||||
.setDescription(`Removed cloop \`${args[1]}\``);
|
||||
channeldc.send({embeds: [Embed]});
|
||||
} else if (args[0] === 'removeall') {
|
||||
clear();
|
||||
clear(bot);
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Cloop')
|
||||
|
|
15
index.js
15
index.js
|
@ -1,3 +1,6 @@
|
|||
const readline = require('node:readline');
|
||||
const {stdin: input, stdout: output} = require('node:process');
|
||||
const rl = readline.createInterface({input, output});
|
||||
const config = require('./config');
|
||||
const {createBot} = require('./bot');
|
||||
const {
|
||||
|
@ -8,13 +11,6 @@ const intents = new Intents(['GUILDS', 'GUILD_MESSAGES']);
|
|||
const dcclient = new Client({
|
||||
intents,
|
||||
});
|
||||
// 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 bots = [];
|
||||
|
||||
|
@ -24,12 +20,9 @@ dcclient.on('ready', () => {
|
|||
// await is important cuz the function is async
|
||||
// VVVVV
|
||||
const bot = await createBot(server, config, getBots, dcclient);
|
||||
bot.console.setRl(rl);
|
||||
bots.push(bot);
|
||||
});
|
||||
});
|
||||
|
||||
dcclient.login(config.discord.token);
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.log(error);
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const moment = require('moment-timezone');
|
||||
const util = require('util');
|
||||
|
||||
function inject(bot, _dcclient, config, rl) {
|
||||
function inject(bot, _dcclient, config) {
|
||||
if (!config.console) return;
|
||||
|
||||
const chatMessage = require('prismarine-chat')(bot.version);
|
||||
|
@ -16,6 +16,8 @@ function inject(bot, _dcclient, config, rl) {
|
|||
|
||||
bot.console = {};
|
||||
bot.console.host = 'all';
|
||||
bot.console._rl = null;
|
||||
bot.console.setRl = setRl;
|
||||
bot.console.log = function(message) {
|
||||
log(prefix('&6LOG', message));
|
||||
};
|
||||
|
@ -26,115 +28,120 @@ function inject(bot, _dcclient, config, rl) {
|
|||
log(prefix('&cERROR', typeof error === 'string' ? error : error.stack));
|
||||
};
|
||||
|
||||
bot.consoleQueue = [];
|
||||
const consoleQueueInterval = setInterval(function() {
|
||||
if (!bot.messageLogging) return;
|
||||
if (bot.consoleQueue.length > 50) bot.consoleQueue = [];
|
||||
if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') {
|
||||
bot.console.log(bot.consoleQueue[0].substring(0, 10000));
|
||||
bot.consoleQueue.shift();
|
||||
}
|
||||
}, 100);
|
||||
// bot.consoleQueue = [];
|
||||
// const consoleQueueInterval = setInterval(function() {
|
||||
// if (!bot.messageLogging) return;
|
||||
// if (bot.consoleQueue.length > 50) bot.consoleQueue = [];
|
||||
// if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') {
|
||||
// bot.console.log(bot.consoleQueue[0].substring(0, 10000));
|
||||
// bot.consoleQueue.shift();
|
||||
// }
|
||||
// }, 100);
|
||||
|
||||
bot.on('parsed_chat', (message) => {
|
||||
bot.consoleQueue.push(message.toAnsi());
|
||||
if (!bot.messageLogging) return;
|
||||
bot.console.log(message.toAnsi());
|
||||
});
|
||||
|
||||
bot.once('end', () => {
|
||||
clearInterval(consoleQueueInterval);
|
||||
rl.removeAllListeners();
|
||||
});
|
||||
// bot.once('end', () => {
|
||||
// clearInterval(consoleQueueInterval);
|
||||
// rl.removeAllListeners();
|
||||
// });
|
||||
|
||||
// readline > fix on log
|
||||
function log(...args) {
|
||||
rl.output.write('\x1b[2K\r');
|
||||
bot.console._rl.output.write('\x1b[2K\r');
|
||||
console.log(args.toString());
|
||||
rl._refreshLine();
|
||||
bot.console._rl._refreshLine();
|
||||
};
|
||||
|
||||
rl.on('line', function(line) {
|
||||
try {
|
||||
if (line.toLowerCase() === '' ||
|
||||
line.toLowerCase().startsWith(' ')) return;
|
||||
function setRl(rl) {
|
||||
bot.console._rl = rl;
|
||||
|
||||
if (line.startsWith('.csvr ')) {
|
||||
const host = line.substring(6);
|
||||
bot.getBots().forEach((bot) => bot.console.host = host);
|
||||
bot.console.info(`Host set to: ${host}`);
|
||||
return;
|
||||
}
|
||||
rl.on('line', function(line) {
|
||||
try {
|
||||
if (line.toLowerCase() === '' ||
|
||||
line.toLowerCase().startsWith(' ')) return;
|
||||
|
||||
if (bot.options.host !== bot.console.host && bot.console.host !== 'all') 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'});
|
||||
if (line.startsWith('.csvr ')) {
|
||||
const host = line.substring(6);
|
||||
bot.getBots().forEach((eachBot) => eachBot.console.host = host);
|
||||
bot.console.info(`Host set to: ${host}`);
|
||||
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(
|
||||
bot.username,
|
||||
bot.username,
|
||||
'*' + line.substring(1),
|
||||
bot.uuid,
|
||||
null,
|
||||
'h',
|
||||
'o',
|
||||
);
|
||||
if (bot.options.host !== bot.console.host && bot.console.host !== 'all') 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(
|
||||
bot.username,
|
||||
bot.username,
|
||||
'*' + line.substring(1),
|
||||
bot.uuid,
|
||||
null,
|
||||
'h',
|
||||
'o',
|
||||
);
|
||||
}
|
||||
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) {
|
||||
bot.console.error(e);
|
||||
}
|
||||
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) {
|
||||
bot.console.error(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {inject};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable require-jsdoc */
|
||||
/* eslint-disable max-len */
|
||||
const {escapeMarkdown} = require('../util/escapeMarkdown');
|
||||
async function inject(bot, dcclient, config, rl) {
|
||||
async function inject(bot, dcclient, config) {
|
||||
const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host]);
|
||||
|
||||
let queue = '';
|
||||
|
|
|
@ -8,19 +8,15 @@ const path = require('path');
|
|||
* @param {object} bot the bot object
|
||||
* @param {object} dcclient discord client
|
||||
* @param {object} config the config
|
||||
* @param {object} rl readline
|
||||
* @param {object} targetClient proxy target
|
||||
* @param {object} client proxy client
|
||||
* @param {boolean} proxy is proxy
|
||||
*/
|
||||
async function loadPlugins(bot, dcclient, config, rl) {
|
||||
async function loadPlugins(bot, dcclient, config) {
|
||||
const dir = path.join(__dirname, '..', 'plugins');
|
||||
const plugins = await fs.readdir(dir);
|
||||
plugins.forEach((plugin) => {
|
||||
if (!plugin.endsWith('.js')) return;
|
||||
try {
|
||||
const plug = require(path.join(dir, plugin));
|
||||
plug.inject(bot, dcclient, config, rl);
|
||||
plug.inject(bot, dcclient, config);
|
||||
} catch (e) {
|
||||
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
|
||||
console.log(util.inspect(e));
|
||||
|
|
Loading…
Reference in a new issue