Add self tree detection

This commit is contained in:
Skylar Grant 2023-01-23 19:37:51 -05:00
parent e26d6dca7d
commit f1570566e8
3 changed files with 30 additions and 15 deletions

View File

@ -1 +1 @@
{"269250657809072139":{"treeMessageId":"1042987280954032158","treeChannelId":"1042987243670872154","rankMessageId":"1065390277767987210","rankChannelId":"1042987923928256553","rankings":[{"rank":"111","name":"Taboo Tree","height":"3030.0"},{"rank":"112","name":"booster tree","height":"3029.0"},{"rank":"113","name":"Pod Birch","height":"3017.0"},{"rank":"114","name":"Wise Mystical Tree","height":"3013.0"},{"rank":"115","name":"Shimmer Doge DAO Tree","height":"2978.9"},{"rank":"116","name":"Simon","height":"2969.1"},{"rank":"117","name":"Cloud Tree","height":"2959.6"},{"rank":"118","name":"The Monke Tree","height":"2947.3"},{"rank":"119","name":"Woody","height":"2925.6"},{"rank":"120","name":"Azure Woodku","height":"2908.0"}],"treeHeight":"179.1"},"803049831839956992":{"treeMessageId":"1052343193980645376","treeChannelId":"1022324601864331335","rankMessageId":"1065121016604524544","rankChannelId":"1022324665374474341","rankings":[{"rank":"1 ","name":"WLR's Ultimate Sudowoodo","height":14203.5},{"rank":"2 ","name":"Our Bonfire Tree","height":13572.9},{"rank":"3 ","name":"The Gremlin Tree","height":12968},{"rank":"4 ","name":"World Tree","height":10600.6},{"rank":"5 ","name":"Emory's Baby","height":10163.9},{"rank":"6 ","name":"Charles the Tree","height":9920},{"rank":"7 ","name":"SMMO-Babel","height":9397},{"rank":"8 ","name":"Spaghetti","height":9341},{"rank":"9 ","name":"the fortnite tree","height":8883},{"rank":"10","name":"TreeVana","height":8002.6}],"treeHeight":261},"1006579138909458513":{"treeMessageId":"1065399196682821713","treeChannelId":"1065398553528250369","rankMessageId":"1065399316979662928","rankChannelId":"1065398553528250369","rankings":[{"rank":"1 ","name":"WLR's Ultimate Sudowoodo","height":"14232.9"},{"rank":"2 ","name":"Our Bonfire Tree","height":"13612.1"},{"rank":"3 ","name":"The Gremlin Tree","height":"12994.8"},{"rank":"4 ","name":"World Tree","height":"10623.0"},{"rank":"5 ","name":"Emory's Baby","height":"10187.8"},{"rank":"6 ","name":"Charles the Tree","height":"9951.0"},{"rank":"7 ","name":"SMMO-Babel","height":"9438.0"},{"rank":"8 ","name":"Spaghetti","height":"9365.0"},{"rank":"9 ","name":"the fortnite tree","height":"8895.0"},{"rank":"10","name":"TreeVana","height":"8019.2"}],"treeHeight":"7941.9"},"760701839427108874":{"treeMessageId":"1065405516400042114","treeChannelId":"1050272057839067178","rankMessageId":"1051889574365904907","rankChannelId":"1050272057839067178","rankings":[{"rank":"251","name":"Bom","height":"1621.0"},{"rank":"252","name":"Tree Of Happiness","height":"1621.0"},{"rank":"253","name":"Treehouse","height":"1604.0"},{"rank":"254","name":"Viktoria II","height":"1595.0"},{"rank":"255","name":"tree of virginity","height":"1588.0"},{"rank":"256","name":"nick's pride","height":"1588.0"},{"rank":"257","name":"Vitraya Ramunong","height":"1583.0"},{"rank":"258","name":"oven tree","height":"1538.7"},{"rank":"259","name":"Tr3e","height":"1527.1"},{"rank":"260","name":"Dicecraft","height":"1523.0"}],"treeHeight":"1527.1"},"868542949737246730":{"treeMessageId":"1065417587502092328","treeChannelId":"1065417555445043300","rankMessageId":"1065417630581801100","rankChannelId":"1065417587502092328","rankings":[{"rank":"1 ","name":"WLR's Ultimate Sudowoodo","height":"14233.4"},{"rank":"2 ","name":"Our Bonfire Tree","height":"13612.7"},{"rank":"3 ","name":"The Gremlin Tree","height":"12995.3"},{"rank":"4 ","name":"World Tree","height":"10623.8"},{"rank":"5 ","name":"Emory's Baby","height":"10188.1"},{"rank":"6 ","name":"Charles the Tree","height":"9951.0"},{"rank":"7 ","name":"SMMO-Babel","height":"9438.4"},{"rank":"8 ","name":"Spaghetti","height":"9365.5"},{"rank":"9 ","name":"the fortnite tree","height":"8895.0"},{"rank":"10","name":"TreeVana","height":"8020.0"}],"treeHeight":"7.0"}} {"868542949737246730":{"treeMessageId":"1065417587502092328","treeChannelId":"1065417555445043300","rankMessageId":"1067237831841419436","rankChannelId":"1065417555445043300","treeName":"voidf1sh Development","treeHeight":"8.0","rankings":[{"rank":"13771","name":"voidf1sh Development","height":"8.0","myTree":true,"maybeMyTree":false},{"rank":"13772","name":"Tree of the true","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13773","name":"Conner Jay Bleach Cox","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13774","name":"cannabi","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13775","name":"Afra the Dwarf","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13776","name":"Alfonso","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13777","name":"The Magnolia Tree","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13778","name":"tree of rage","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13779","name":"weepin' willow","height":"8.0","myTree":false,"maybeMyTree":false},{"rank":"13780","name":"Drzewo Pingwinow","height":"8.0","myTree":false,"maybeMyTree":false}]}}

View File

@ -71,7 +71,7 @@ const functions = {
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setColor(0xFF0000) .setColor(0xFF0000)
.setTitle('Error!') .setTitle('Error!')
.setDescription(content) .setDescription("Error: " + content)
.setFooter({ text: strings.embeds.footer }); .setFooter({ text: strings.embeds.footer });
const messageContents = { embeds: [embed], ephemeral: true }; const messageContents = { embeds: [embed], ephemeral: true };
return messageContents; return messageContents;
@ -118,11 +118,17 @@ const functions = {
trimmedName = trimmedName.slice(0, trimmedName.indexOf('``')); trimmedName = trimmedName.slice(0, trimmedName.indexOf('``'));
let trimmedHeight = parseFloat(breakdown[2].slice(0, breakdown[2].indexOf('ft'))).toFixed(1); let trimmedHeight = parseFloat(breakdown[2].slice(0, breakdown[2].indexOf('ft'))).toFixed(1);
let isMyTree = false;
let isMaybeMyTree = false;
if (breakdown[2].includes('📍')) isMyTree = true;
if (breakdown[1].includes(guildInfo[interaction.guildId].treeName)) maybeMyTree = true;
rankings.push({ rankings.push({
rank: trimmedRank, rank: trimmedRank,
name: trimmedName, name: trimmedName,
height: trimmedHeight height: trimmedHeight,
myTree: isMyTree,
maybeMyTree: isMaybeMyTree
}); });
} }
@ -146,22 +152,28 @@ const functions = {
let treeHeight = parseFloat(guildInfo[interaction.guildId].treeHeight).toFixed(1); let treeHeight = parseFloat(guildInfo[interaction.guildId].treeHeight).toFixed(1);
if ((guildInfo[interaction.guildId].rankings.length > 0) && (treeHeight > 0)) { if ((guildInfo[interaction.guildId].rankings.length > 0) && (treeHeight > 0)) {
let replyString = 'Current Tree Height: ' + treeHeight + 'ft\n\n'; let replyString = 'Current Tree Height: ' + treeHeight + 'ft\n\n';
guildInfo[interaction.guildId].rankings.forEach(e => { guildInfo[interaction.guildId].rankings.forEach(treeRanking => {
let difference = parseFloat(e.height).toFixed(1) - treeHeight; let difference = parseFloat(treeRanking.height).toFixed(1) - treeHeight;
let decimal = (e.height % 1).toFixed(1); let decimal = (treeRanking.height % 1).toFixed(1);
let growthIndicator = ""; let growthIndicator = "";
if (decimal > 0) { if (decimal > 0) {
growthIndicator += "[+]"; growthIndicator += "[+]";
} }
const absDifference = parseFloat(Math.abs(difference)).toFixed(1); const absDifference = parseFloat(Math.abs(difference)).toFixed(1);
if (treeRanking.myTree) {
replyString += "This is your tree. ";
} else if (treeRanking.maybeMyTree) {
replyString += "This might be your tree. Same height, same name. ";
} else {
if (difference > 0) { if (difference > 0) {
replyString += `#${e.rank} - ${absDifference}ft${growthIndicator} shorter `; replyString += `#${treeRanking.rank} - ${absDifference}ft${growthIndicator} shorter `;
} else if (difference < 0) { } else if (difference < 0) {
replyString += `#${e.rank} - ${absDifference}ft${growthIndicator} taller `; replyString += `#${treeRanking.rank} - ${absDifference}ft${growthIndicator} taller `;
} else if (difference == 0) { } else if (difference == 0) {
replyString += `#${e.rank} - Same height${growthIndicator} `; replyString += `#${treeRanking.rank} - Same Height${growthIndicator} `;
} }
replyString += `[${functions.getWaterTime(e.height)}m]\n`; }
replyString += `[${functions.getWaterTime(treeRanking.height)} mins]\n`;
}); });
return 'Here\'s how your tree compares: \n' + replyString; return 'Here\'s how your tree compares: \n' + replyString;
} else { } else {
@ -186,8 +198,10 @@ const functions = {
return; return;
} }
input = m.embeds[0].data.description; input = m.embeds[0].data.description;
let treeName = m.embeds[0].data.title;
let lines = input.split('\n'); let lines = input.split('\n');
guildInfo[interaction.guildId].treeHeight = parseFloat(lines[0].slice(lines[0].indexOf('is') + 3, lines[0].indexOf('ft'))).toFixed(1); guildInfo[interaction.guildId].treeHeight = parseFloat(lines[0].slice(lines[0].indexOf('is') + 3, lines[0].indexOf('ft'))).toFixed(1);
guildInfo[interaction.guildId].treeName = treeName;
fs.writeFileSync('./data/guildInfo.json', JSON.stringify(guildInfo)); fs.writeFileSync('./data/guildInfo.json', JSON.stringify(guildInfo));
guildInfo = require('../data/guildInfo.json'); guildInfo = require('../data/guildInfo.json');
resolve("The reference tree message has been saved/updated."); resolve("The reference tree message has been saved/updated.");

View File

@ -13,8 +13,9 @@ module.exports = {
"treeChannelId": "", "treeChannelId": "",
"rankMessageId": "", "rankMessageId": "",
"rankChannelId": "", "rankChannelId": "",
"rankings": [], "treeName": "",
"treeHeight": 0 "treeHeight": 0,
"rankings": []
}; };
} }
interaction.channel.messages.fetch({ limit: 20 }).then(msgs => { interaction.channel.messages.fetch({ limit: 20 }).then(msgs => {