From b00a127d4a4b5b920b6d66e1f2ec0d10058e9b93 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 2 Jul 2024 22:03:48 -0600 Subject: [PATCH] Add code for when color formatting shit --- index.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2812151..5861e1d 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,29 @@ const doAddressHistory = (userid, address) => { fs.writeFileSync("./history.json", JSON.stringify(addressHistory)); } +function flattenDescription(jsonData) { + const description = jsonData.description; + let flattenedString = ""; + + function traverse(obj) { + if (typeof obj === "object") { + if (Array.isArray(obj)) { + obj.forEach(traverse); + } else { + if (obj.text) { + flattenedString += obj.text; + } + if (obj.extra) { + obj.extra.forEach(traverse); + } + } + } + } + + traverse(description); + return flattenedString.trim(); +} + client.on('interactionCreate', async interaction => { if (interaction.isCommand()) { switch (interaction.commandName) { @@ -102,9 +125,14 @@ client.on('interactionCreate', async interaction => { const address = interaction.options.getString("address"); doAddressHistory(interaction.user.id, address); findMc(address, 5000).then((data) => { - data.description = filterMOTD(data.description); - motd = `\`${data.description.split("\n")[0]}\`` - if (data.description?.split("\n")[1]) motd += "\n" + `\`${data.description.split("\n")[1]}\`` + if (typeof data.description === "object") { + data.description = flattenDescription(data); + } else { + data.description = filterMOTD(data.description); + } + + motd = `\`${data.description.split("\n")[0]}\``; + if (data.description.split("\n")[1]) motd += `\n\`${data.description.split("\n")[1]}\``; msgData = { embeds: [{ title: `Server Info for ${address}`, @@ -162,7 +190,7 @@ client.on('interactionCreate', async interaction => { break; } } - if(interaction.isAutocomplete()) { + if (interaction.isAutocomplete()) { // Send their history as options const history = addressHistory[interaction.user.id] || []; // Map the history to options