Adjust readiness detection system
This commit is contained in:
parent
a1b9ea9fcb
commit
1b0148a32f
@ -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("<t:") + 3;
|
||||
const endWaterTimestamp = 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user