From 0f83678bfa9676f3c6e40dc2666c37d1e87c2e35 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 27 Jan 2023 20:57:40 -0500 Subject: [PATCH] New water readiness system --- main.js | 2 +- modules/dbfn.js | 22 +++++++++++++++------- modules/functions.js | 24 ++++++++++++------------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/main.js b/main.js index 7ca988a..8a7c30d 100644 --- a/main.js +++ b/main.js @@ -60,7 +60,7 @@ client.on('interactionCreate', async interaction => { fn.refresh(interaction); } else if (interaction.isButton() && interaction.component.customId == 'resetping') { fn.resetPing(interaction); - interaction.reply({ content: "Reset water readiness detection system.", ephemeral: true }); + interaction.reply({ content: "Water Readiness Detection System: [ARMED]", ephemeral: true }); } }); diff --git a/modules/dbfn.js b/modules/dbfn.js index e70b63f..ca55da4 100644 --- a/modules/dbfn.js +++ b/modules/dbfn.js @@ -115,8 +115,8 @@ module.exports = { "treeChannelId": row.tree_channel_id, "leaderboardMessageId": row.leaderboard_message_id, "leaderboardChannelId": row.leaderboard_channel_id, - "pingRoleId": row.ping_role_id, - "pingChannelId": row.ping_channel_id, + "reminderMessage": row.ping_role_id, + "reminderChannelId": row.ping_channel_id, "remindedStatus": row.reminded_status }; db.end(); @@ -329,12 +329,20 @@ module.exports = { reject("Error fetching the historic 24hr tree height: " + err.message); return; } - const hist24hTree = { - "treeName": res[0].tree_name, - "treeRank": res[0].tree_rank, - "treeHeight": res[0].tree_height, - "hasPin": res[0].has_pin + let hist24hTree = {}; + if (res.length > 0) { + hist24hTree = { + "treeName": res[0].tree_name, + "treeRank": res[0].tree_rank, + "treeHeight": res[0].tree_height, + "hasPin": res[0].has_pin + } + } else { + hist24hTree = { + + } } + db.end(); resolve({ "status": "Successfully fetched historic 24hr tree.", "data": hist24hTree }); }); diff --git a/modules/functions.js b/modules/functions.js index 950e8e0..848bf1f 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -79,7 +79,7 @@ const functions = { const embed = new EmbedBuilder() .setColor(strings.embeds.color) .setTitle('Water Reminder') - .setDescription(`${content}\n[Your Tree](https://discord.com/channels/${guildInfo.guildId}/${guildInfo.treeChannelId}/${guildInfo.treeMessageId})`) + .setDescription(`${content}\n[Click Here To Go To Your Tree](https://discord.com/channels/${guildInfo.guildId}/${guildInfo.treeChannelId}/${guildInfo.treeMessageId})`) .setFooter({text: `This message will self-destruct in 60 seconds...`}); const messageContents = { embeds: [embed] }; return messageContents; @@ -208,18 +208,18 @@ const functions = { for (let i = leaderboard.length - 1; i >= 0; i--) { const leaderboardEntry = leaderboard[i]; // Setup the status indicator, default to blank, we'll change it later - let statusIndicator = "``["; - if ((leaderboardEntry.treeHeight % 1).toFixed(1) > 0) statusIndicator += "💧|"; + let statusIndicator = ""; + if ((leaderboardEntry.treeHeight % 1).toFixed(1) > 0) statusIndicator += "``[💧]``"; // Get the data for this tree from 24 hours ago - const get24hTreeResponse = await dbfn.get24hTree(interaction.guildId, leaderboardEntry.treeName); - const dayAgoTree = get24hTreeResponse.data; - const hist24hDifference = (leaderboardEntry.treeHeight - dayAgoTree.treeHeight).toFixed(1); - statusIndicator += `+${hist24hDifference}ft|` + // const get24hTreeResponse = await dbfn.get24hTree(interaction.guildId, leaderboardEntry.treeName); + // const dayAgoTree = get24hTreeResponse.data; + // const hist24hDifference = (leaderboardEntry.treeHeight - dayAgoTree.treeHeight).toFixed(1); + // statusIndicator += `+${hist24hDifference}ft|` // Get the 24h watering time for this tree - const totalWaterTime = await functions.timeToHeight(dayAgoTree.treeHeight, leaderboardEntry.treeHeight); - statusIndicator += `${totalWaterTime}]\`\``; + // const totalWaterTime = await functions.timeToHeight(dayAgoTree.treeHeight, leaderboardEntry.treeHeight); + // statusIndicator += `${totalWaterTime}]\`\``; // Determine if this tree is the guild's tree if (leaderboardEntry.hasPin) { @@ -235,7 +235,7 @@ const functions = { } } // Build a string using the current leaderboard entry and the historic entry from 24 hours ago - comparisonReplyString += `\n${statusIndicator}\n`; + comparisonReplyString += `${statusIndicator}\n`; // if (process.env.isDev == 'true') comparisonReplyString += `Current Height: ${leaderboardEntry.treeHeight} 24h Ago Height: ${dayAgoTree.treeHeight}\n`; } return comparisonReplyString; @@ -398,13 +398,13 @@ const functions = { const treeMessage = await treeChannel.messages.fetch(treeMessageId); const readyToWater = treeMessage.embeds[0].description.includes('Ready to be watered'); if (readyToWater) { - console.log("Ready to water"); + // console.log("Ready to water"); this.sendReminder(guildInfo, guild); this.sleep(5000).then(() => { this.checkReady(client); }); } else { - console.log("Not ready to water"); + // console.log("Not ready to water"); this.sleep(5000).then(() => { this.checkReady(client); });