From 5e08befb6b1e20b1073e25dbd335b48af4fc3c5b Mon Sep 17 00:00:00 2001 From: Parker2991 Date: Fri, 30 Aug 2024 12:23:48 -0400 Subject: [PATCH] vanilla chat fixes --- src/index.js | 7 ------- src/modules/console.js | 6 +++--- src/modules/discord.js | 4 +--- src/util/ChatParsers/ChipmunkMod.js | 20 ++++++-------------- src/util/ChatParsers/Kaboom.js | 4 ++-- src/util/ChatParsers/VanillaChat.js | 16 +++------------- src/util/ChatParsers/sayConsole.js | 11 +---------- 7 files changed, 16 insertions(+), 52 deletions(-) diff --git a/src/index.js b/src/index.js index aebcfe8..d1b592d 100644 --- a/src/index.js +++ b/src/index.js @@ -33,10 +33,3 @@ for (const options of config.bots) { loadModules(bot, options, config, discordClient); bot.console.useReadlineInterface(rl); } -/*config.bots.filter((options) => { - const bot = createBot(options, config); - bots.push(bot); - bot.bots = bots; - loadModules(bot, options, config, discordClient); - bot.console.useReadlineInterface(rl); -})*/ diff --git a/src/modules/console.js b/src/modules/console.js index beda220..0bea6db 100644 --- a/src/modules/console.js +++ b/src/modules/console.js @@ -22,8 +22,8 @@ function CommandConsole (bot, options, config) { rl.output.write("\x1b[2K\r"); console.log(args.toString()); rl._refreshLine(); - } - } + } + } } bot.console.logs = function (message) { log(ChatMessage.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §6logs§8] §8[${options.serverName}§8] `)?.toAnsi() + message) @@ -38,7 +38,7 @@ function CommandConsole (bot, options, config) { bot.console.source.sendFeedback = message => { const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt") if (!options.logging) return - bot.console.logs(ChatMessage.fromNotch('§8[§6Command§8]')?.toAnsi() + ansi); + bot.console.logs(ChatMessage.fromNotch('§8[§6Command§8] ')?.toAnsi() + ansi); } bot.console.error = function (message) { console.log(ChatMessage.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §4error§8] §8[${options.serverName}§8] `)?.toAnsi() + message) diff --git a/src/modules/discord.js b/src/modules/discord.js index 92dd16b..5f0c92b 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -8,7 +8,6 @@ const client = new Client({ intents: [Guilds, GuildMessages, MessageContent] }) const util = require('util') function discord(bot, options, config, discordClient) { -// client.login(config.discord.token) if (!options?.channelId) { bot.discord = { invite: config.discord?.invite @@ -40,8 +39,7 @@ function discord(bot, options, config, discordClient) { try { bot?.discord?.channel?.send(`\`\`\`ansi\n${discordQueue.join('\n').substring(0, 1984)}\n\`\`\``) } catch (error) { - bot.console.error(error.toString()) - + bot.console.warn(error.toString()) } discordQueue = [] }, 2000) diff --git a/src/util/ChatParsers/ChipmunkMod.js b/src/util/ChatParsers/ChipmunkMod.js index 52f3f35..bc3b08e 100644 --- a/src/util/ChatParsers/ChipmunkMod.js +++ b/src/util/ChatParsers/ChipmunkMod.js @@ -1,35 +1,27 @@ -function chipmunkmod (message, data, context, bot) { +function ChipmunkMod (message, data, context, bot) { try { - if (message === null || typeof message !== 'object') return - + if (message === null || typeof message !== 'object') return if (message.with?.length < 3 || (message.translate !== '[%s] %s › %s' && message.translate !== '%s %s › %s')) return const senderComponent = message.with[1] - // wtf spam again - - //console.log(senderComponent)//wtf... - - const contents = message.with[2] -// spam lol - console.log(contents) let sender - const hoverEvent = senderComponent.hoverEvent - //console.log(JSON.stringify(hoverEvent)) if (hoverEvent?.action === 'show_entity') { const id = hoverEvent.contents.id -// + sender = data.players.find(player => player.uuid === id) } else { const stringUsername = data.getMessageAsPrismarine(senderComponent).toString() // TypeError: data.getMessageAsPrismarine is not a function - sender = data.players.find(player => player.profile.name) //=== stringusername) + sender = data.players.find(player => player.profile.name === stringUsername) } if (!sender) return null return { sender, contents, type: 'minecraft:chat', senderComponent } } catch(e) { - console.error(e) + console.error(e) } } -module.exports = chipmunkmod +module.exports = ChipmunkMod diff --git a/src/util/ChatParsers/Kaboom.js b/src/util/ChatParsers/Kaboom.js index 880b5bf..9d0c123 100644 --- a/src/util/ChatParsers/Kaboom.js +++ b/src/util/ChatParsers/Kaboom.js @@ -1,6 +1,6 @@ const util = require('util') -function parseMessage (message, data) { +function kaboom (message, data) { if (message === null || typeof message !== 'object') return if (message.text !== '' || !Array.isArray(message.extra) || message.extra.length < 3) return @@ -38,4 +38,4 @@ function isSeparatorAt (children, start) { return (children[start]?.text === ':' || children[start]?.text === '\xa7f:') && children[start + 1]?.text === ' ' } -module.exports = parseMessage +module.exports = kaboom diff --git a/src/util/ChatParsers/VanillaChat.js b/src/util/ChatParsers/VanillaChat.js index 4a1b1fe..3b489c1 100644 --- a/src/util/ChatParsers/VanillaChat.js +++ b/src/util/ChatParsers/VanillaChat.js @@ -3,31 +3,21 @@ function VanillaChat (message, data, context) { if (message === null || typeof message !== 'object') return if (message.with?.length < 2 || (message.translate !== 'chat.type.text' && message.translate !== '%s %s')) return - - const senderComponent = message.with[0] - // wtf spam again - console.log(senderComponent)//wtf... -//console.log(senderComponent) - + const senderComponent = message.with[0] const contents = message.with[1] -// spam lol - console.log(contents) - //console.log(contents) let sender - const hoverEvent = senderComponent.hoverEvent if (hoverEvent?.action === 'show_entity') { const id = hoverEvent.contents.id -// sender = data.players.find(player => player.uuid === id) } else { const stringUsername = data.getMessageAsPrismarine(senderComponent).toString() // TypeError: data.getMessageAsPrismarine is not a function - - sender = data.players.find(player => player.profile.name) //=== stringusername) + sender = data.players.find(player => player.profile.name === stringUsername) } - if (!sender) return undefined return { sender, contents, type: 'minecraft:chat', senderComponent } - } catch(e) { + } catch(e) { console.log(e.stack) } } diff --git a/src/util/ChatParsers/sayConsole.js b/src/util/ChatParsers/sayConsole.js index 2c3b57e..e274b53 100644 --- a/src/util/ChatParsers/sayConsole.js +++ b/src/util/ChatParsers/sayConsole.js @@ -5,31 +5,22 @@ function sayConsole (message, data, context, bot) { if (message.with?.length < 2 || (message.translate !== 'chat.type.announcement' && message.translate !== '%s %s')) return const senderComponent = message.with[0] - // wtf spam again - - //console.log(senderComponent)//wtf... - - const contents = message.with[1] -// spam lol - console.log(contents) let sender - const hoverEvent = senderComponent.hoverEvent - //console.log(JSON.stringify(hoverEvent)) if (hoverEvent?.action === 'show_entity') { const id = hoverEvent?.contents?.id -// sender = data.players.find(player => player.uuid === id) } else { const stringUsername = data.getMessageAsPrismarine(senderComponent).toString() // TypeError: data.getMessageAsPrismarine is not a function sender = data.players.find(player => player.profile.name) //=== stringusername) } - if (!sender) return null return { sender, contents, type: 'minecraft:chat', senderComponent } } catch(e) { - console.error(e) + console.error(e); } } module.exports = sayConsole