Adjust readiness detection system

This commit is contained in:
Skylar Grant 2023-01-30 21:38:12 -05:00
parent a1b9ea9fcb
commit 1b0148a32f

View File

@ -554,41 +554,53 @@ const functions = {
// Would also be helpful to have an opt-in or opt-out ability for water checks // Would also be helpful to have an opt-in or opt-out ability for water checks
try { try {
const getOptedInGuildsResponse = await dbfn.getOptedInGuilds(); const getOptedInGuildsResponse = await dbfn.getOptedInGuilds();
// console.log(JSON.stringify(getOptedInGuildsResponse));
if (getOptedInGuildsResponse.status != "No servers have opted in yet") { if (getOptedInGuildsResponse.status != "No servers have opted in yet") {
const guilds = getOptedInGuildsResponse.data; 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; const { guildId, treeChannelId, treeMessageId, remindedStatus } = guildInfo;
if (remindedStatus == 0) { if (remindedStatus == 0) {
const guild = await client.guilds.fetch(guildId); const guild = await client.guilds.fetch(guildId);
const treeChannel = await guild.channels.fetch(treeChannelId); const treeChannel = await guild.channels.fetch(treeChannelId);
const treeMessage = await treeChannel.messages.fetch(treeMessageId); 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("<t:") + 3;
const endWaterTimestamp = description.indexOf(":>");
const waterTimestamp = parseInt(description.slice(beginWaterTimestamp, endWaterTimestamp));
const nowTimestamp = (Date.now() / 1000);
const readyToWater = (nowTimestamp > waterTimestamp);
if (readyToWater) { if (readyToWater) {
// console.log("Ready to water"); // console.log("Ready to water");
await this.sendReminder(guildInfo, guild); await this.sendReminder(guildInfo, guild);
await this.sleep(5000).then(() => { this.sleep(5000).then(async () => {
this.checkReady(client); await this.checkReady(client);
}); });
return;
} else { } else {
// console.log("Not ready to water"); // console.log("Not ready to water\n" + `Water At: ${waterTimestamp} | Now: ${nowTimestamp}`);
await this.sleep(5000).then(() => { this.sleep(5000).then(async () => {
this.checkReady(client); await this.checkReady(client);
}); });
return;
} }
} }
}); });
} else { } else {
// console.log(getOptedInGuildsResponse.status); // console.log(getOptedInGuildsResponse.status);
await this.sleep(5000).then(() => { this.sleep(5000).then(async () => {
this.checkReady(client); await this.checkReady(client);
}); });
return;
} }
} catch (err) { } catch (err) {
console.error(err); console.error(err);
await this.sleep(5000).then(() => { this.sleep(5000).then(async () => {
this.checkReady(client); await this.checkReady(client);
}); });
return;
} }
}, },
async resetPing(interaction) { async resetPing(interaction) {