From b23f46bff802ec6de61e3722807a05cfbf8d2b49 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Thu, 17 Nov 2022 10:30:51 +0700 Subject: [PATCH] move custom chat to plugins + fix list --- commands/list.js | 2 +- plugins/commands.js | 2 +- plugins/proxy.js | 21 ---------------- plugins/proxy/custom_chat_formatting.js | 32 +++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 plugins/proxy/custom_chat_formatting.js diff --git a/commands/list.js b/commands/list.js index 3041bc9..39b183d 100644 --- a/commands/list.js +++ b/commands/list.js @@ -6,7 +6,7 @@ module.exports = { description: 'List players', usage: '', trusted: 0, - execute: async function(bot) { + execute: async function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) { try { const component = []; component.push({text: 'Players ', color: 'green'}); diff --git a/plugins/commands.js b/plugins/commands.js index 6dc6fab..6891422 100644 --- a/plugins/commands.js +++ b/plugins/commands.js @@ -38,7 +38,7 @@ function inject(bot, dcclient, config) { .setDescription(`\`\`\`${e}\`\`\``); channeldc.send({embeds: [Embed]}); } else { - bot.tellraw('@a', {text: String(e), color: 'red'}); + bot.tellraw(selector, {text: String(e), color: 'red'}); } } }; diff --git a/plugins/proxy.js b/plugins/proxy.js index 432f90f..dfd06cc 100644 --- a/plugins/proxy.js +++ b/plugins/proxy.js @@ -9,8 +9,6 @@ function inject(bot, dcclient, config) { index = _index; }); - const {MessageBuilder} = require('prismarine-chat')(bot.version); - const version = bot.version; const srv = mc.createServer({ 'online-mode': false, @@ -78,25 +76,6 @@ function inject(bot, dcclient, config) { client.username, ); } - bot.tellraw('@a', { - color: 'dark_gray', - translate: '[%s] [%s] %s \u203a %s', - with: [ - { - text: 'Chat', - color: 'gray', - }, - { - text: 'Proxy', - color: 'gray', - }, - { - text: client.username, - color: 'green', - }, - MessageBuilder.fromString('&7' + data.message), - ], - }); return; } targetClient.write(meta.name, data); diff --git a/plugins/proxy/custom_chat_formatting.js b/plugins/proxy/custom_chat_formatting.js new file mode 100644 index 0000000..8dea2cc --- /dev/null +++ b/plugins/proxy/custom_chat_formatting.js @@ -0,0 +1,32 @@ +/* eslint-disable require-jsdoc */ +function inject(bot, client, targetClient) { + const {MessageBuilder} = require('prismarine-chat')(bot.version); + client.on('packet', (data, meta) => { + if (meta.name === 'chat' && + !data.message?.startsWith('/') && + !data.message?.startsWith('.') + ) { + bot.tellraw('@a', { + color: 'dark_gray', + translate: '[%s] [%s] %s \u203a %s', + with: [ + { + text: 'Chat', + color: 'gray', + }, + { + text: 'Proxy', + color: 'gray', + }, + { + text: client.username, + color: 'green', + }, + MessageBuilder.fromString('&7' + data.message), + ], + }); + } + }); +}; + +module.exports = {inject};