Add code for when color formatting shit
This commit is contained in:
parent
96d86d0f88
commit
b00a127d4a
32
index.js
32
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) => {
|
||||
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]}\``
|
||||
}
|
||||
|
||||
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}`,
|
||||
|
|
Loading…
Reference in a new issue