Add code for when color formatting shit
This commit is contained in:
parent
96d86d0f88
commit
b00a127d4a
36
index.js
36
index.js
|
@ -94,6 +94,29 @@ const doAddressHistory = (userid, address) => {
|
||||||
fs.writeFileSync("./history.json", JSON.stringify(addressHistory));
|
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 => {
|
client.on('interactionCreate', async interaction => {
|
||||||
if (interaction.isCommand()) {
|
if (interaction.isCommand()) {
|
||||||
switch (interaction.commandName) {
|
switch (interaction.commandName) {
|
||||||
|
@ -102,9 +125,14 @@ client.on('interactionCreate', async interaction => {
|
||||||
const address = interaction.options.getString("address");
|
const address = interaction.options.getString("address");
|
||||||
doAddressHistory(interaction.user.id, address);
|
doAddressHistory(interaction.user.id, address);
|
||||||
findMc(address, 5000).then((data) => {
|
findMc(address, 5000).then((data) => {
|
||||||
data.description = filterMOTD(data.description);
|
if (typeof data.description === "object") {
|
||||||
motd = `\`${data.description.split("\n")[0]}\``
|
data.description = flattenDescription(data);
|
||||||
if (data.description?.split("\n")[1]) motd += "\n" + `\`${data.description.split("\n")[1]}\``
|
} 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 = {
|
msgData = {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: `Server Info for ${address}`,
|
title: `Server Info for ${address}`,
|
||||||
|
@ -162,7 +190,7 @@ client.on('interactionCreate', async interaction => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(interaction.isAutocomplete()) {
|
if (interaction.isAutocomplete()) {
|
||||||
// Send their history as options
|
// Send their history as options
|
||||||
const history = addressHistory[interaction.user.id] || [];
|
const history = addressHistory[interaction.user.id] || [];
|
||||||
// Map the history to options
|
// Map the history to options
|
||||||
|
|
Loading…
Reference in a new issue