Add code for when color formatting shit

This commit is contained in:
Christopher Cookman 2024-07-02 22:03:48 -06:00
parent 96d86d0f88
commit b00a127d4a
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -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