From 1b0148a32fd8664b4c6069a7b216a65e330909a9 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 30 Jan 2023 21:38:12 -0500 Subject: [PATCH] Adjust readiness detection system --- modules/functions.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/modules/functions.js b/modules/functions.js index 6e75037..2fc3c22 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -554,41 +554,53 @@ const functions = { // Would also be helpful to have an opt-in or opt-out ability for water checks try { const getOptedInGuildsResponse = await dbfn.getOptedInGuilds(); + // console.log(JSON.stringify(getOptedInGuildsResponse)); if (getOptedInGuildsResponse.status != "No servers have opted in yet") { const guilds = getOptedInGuildsResponse.data; - guilds.forEach(async guildInfo => { + guilds.forEach(async oldGuildInfo => { + const getGuildInfoResponse = await dbfn.getGuildInfo(oldGuildInfo.guildId); + const guildInfo = getGuildInfoResponse.data; const { guildId, treeChannelId, treeMessageId, remindedStatus } = guildInfo; if (remindedStatus == 0) { const guild = await client.guilds.fetch(guildId); const treeChannel = await guild.channels.fetch(treeChannelId); const treeMessage = await treeChannel.messages.fetch(treeMessageId); - const readyToWater = treeMessage.embeds[0].description.includes('Ready to be watered'); + const description = treeMessage.embeds[0].description; + const beginWaterTimestamp = description.indexOf(""); + const waterTimestamp = parseInt(description.slice(beginWaterTimestamp, endWaterTimestamp)); + const nowTimestamp = (Date.now() / 1000); + const readyToWater = (nowTimestamp > waterTimestamp); if (readyToWater) { // console.log("Ready to water"); await this.sendReminder(guildInfo, guild); - await this.sleep(5000).then(() => { - this.checkReady(client); + this.sleep(5000).then(async () => { + await this.checkReady(client); }); + return; } else { - // console.log("Not ready to water"); - await this.sleep(5000).then(() => { - this.checkReady(client); + // console.log("Not ready to water\n" + `Water At: ${waterTimestamp} | Now: ${nowTimestamp}`); + this.sleep(5000).then(async () => { + await this.checkReady(client); }); + return; } } }); } else { // console.log(getOptedInGuildsResponse.status); - await this.sleep(5000).then(() => { - this.checkReady(client); + this.sleep(5000).then(async () => { + await this.checkReady(client); }); + return; } } catch (err) { console.error(err); - await this.sleep(5000).then(() => { - this.checkReady(client); + this.sleep(5000).then(async () => { + await this.checkReady(client); }); + return; } }, async resetPing(interaction) {