move chat queue to chat plugin

This commit is contained in:
ChomeNS 2022-11-12 16:34:17 +07:00
parent e4c7c59266
commit 946fd88d36
2 changed files with 30 additions and 31 deletions

View file

@ -8,7 +8,6 @@ const config = require('./config');
const crypto = require('crypto');
const colorConvert = require('color-convert');
const sleep = require('sleep-promise');
const {containsIllegalCharacters} = require('./util/containsIllegalCharacters');
const generateEaglerUsername = require('./util/generateEaglerUsername');
const {EventEmitter} = require('events');
const {loadPlugins} = require('./util/loadPlugins');
@ -58,7 +57,6 @@ async function botThings() {
};
bot._client = mc.createClient(bot.options);
bot.version = bot._client.version;
bot.queue = [];
bot.write = (name, data) => bot._client.write(name, data);
bot.end = (reason = 'end') => {
bot.emit('end', reason);
@ -81,35 +79,11 @@ async function botThings() {
function main() {
const channel = dcclient.channels.cache.get(config.discord.servers[process.argv[2]]);
// allink's chat queue
chatQueue = setInterval(function() {
try {
if (bot.queue[0] || bot.queue[0] === '') {
try {
if (containsIllegalCharacters(bot.queue[0])) {
bot.queue.shift();
return;
};
bot.write('chat', {message: bot.queue[0].substring(0, 256)});
bot.queue.shift();
} catch (e) {
console.log(e.message);
}
}
} catch (e) {
return;
}
}, 450);
module.exports = bot;
bot.playersAddedPlayers = {};
bot.getplayerusername = {};
bot.chat = (message) => {
bot.queue.push(String(message));
};
bot.once('end', (reason, event) => {
console.log(
`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`,
@ -130,11 +104,6 @@ function main() {
console.log(e);
}
try {
clearInterval(notonline);
clearInterval(chatQueue);
} catch (e) {}
setTimeout(() => {
bot.end();
botThings();

View file

@ -2,7 +2,37 @@
/* eslint-disable require-jsdoc */
// eslint-disable-next-line no-undef
// const parse = require('../util/text_parser');
const {containsIllegalCharacters} = require('../util/containsIllegalCharacters');
function inject(bot) {
bot.chatQueue = [];
const chatQueue = setInterval(function() {
try {
if (bot.chatQueue[0] || bot.chatQueue[0] === '') {
try {
if (containsIllegalCharacters(bot.chatQueue[0])) {
bot.chatQueue.shift();
return;
};
bot.write('chat', {message: bot.chatQueue[0].substring(0, 256)});
bot.chatQueue.shift();
} catch (e) {
console.log(e.message);
}
}
} catch (e) {
return;
}
}, 450);
bot.chat = (message) => {
bot.chatQueue.push(String(message));
};
bot.once('end', () => {
clearInterval(chatQueue);
});
let previousMessage;
const ChatMessage = require('prismarine-chat')(bot.version);