New water readiness system
This commit is contained in:
parent
431b244997
commit
0f83678bfa
2
main.js
2
main.js
@ -60,7 +60,7 @@ client.on('interactionCreate', async interaction => {
|
|||||||
fn.refresh(interaction);
|
fn.refresh(interaction);
|
||||||
} else if (interaction.isButton() && interaction.component.customId == 'resetping') {
|
} else if (interaction.isButton() && interaction.component.customId == 'resetping') {
|
||||||
fn.resetPing(interaction);
|
fn.resetPing(interaction);
|
||||||
interaction.reply({ content: "Reset water readiness detection system.", ephemeral: true });
|
interaction.reply({ content: "Water Readiness Detection System: [ARMED]", ephemeral: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ module.exports = {
|
|||||||
"treeChannelId": row.tree_channel_id,
|
"treeChannelId": row.tree_channel_id,
|
||||||
"leaderboardMessageId": row.leaderboard_message_id,
|
"leaderboardMessageId": row.leaderboard_message_id,
|
||||||
"leaderboardChannelId": row.leaderboard_channel_id,
|
"leaderboardChannelId": row.leaderboard_channel_id,
|
||||||
"pingRoleId": row.ping_role_id,
|
"reminderMessage": row.ping_role_id,
|
||||||
"pingChannelId": row.ping_channel_id,
|
"reminderChannelId": row.ping_channel_id,
|
||||||
"remindedStatus": row.reminded_status
|
"remindedStatus": row.reminded_status
|
||||||
};
|
};
|
||||||
db.end();
|
db.end();
|
||||||
@ -329,12 +329,20 @@ module.exports = {
|
|||||||
reject("Error fetching the historic 24hr tree height: " + err.message);
|
reject("Error fetching the historic 24hr tree height: " + err.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const hist24hTree = {
|
let hist24hTree = {};
|
||||||
|
if (res.length > 0) {
|
||||||
|
hist24hTree = {
|
||||||
"treeName": res[0].tree_name,
|
"treeName": res[0].tree_name,
|
||||||
"treeRank": res[0].tree_rank,
|
"treeRank": res[0].tree_rank,
|
||||||
"treeHeight": res[0].tree_height,
|
"treeHeight": res[0].tree_height,
|
||||||
"hasPin": res[0].has_pin
|
"hasPin": res[0].has_pin
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
hist24hTree = {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
db.end();
|
db.end();
|
||||||
resolve({ "status": "Successfully fetched historic 24hr tree.", "data": hist24hTree });
|
resolve({ "status": "Successfully fetched historic 24hr tree.", "data": hist24hTree });
|
||||||
});
|
});
|
||||||
|
@ -79,7 +79,7 @@ const functions = {
|
|||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(strings.embeds.color)
|
.setColor(strings.embeds.color)
|
||||||
.setTitle('Water Reminder')
|
.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...`});
|
.setFooter({text: `This message will self-destruct in 60 seconds...`});
|
||||||
const messageContents = { embeds: [embed] };
|
const messageContents = { embeds: [embed] };
|
||||||
return messageContents;
|
return messageContents;
|
||||||
@ -208,18 +208,18 @@ const functions = {
|
|||||||
for (let i = leaderboard.length - 1; i >= 0; i--) {
|
for (let i = leaderboard.length - 1; i >= 0; i--) {
|
||||||
const leaderboardEntry = leaderboard[i];
|
const leaderboardEntry = leaderboard[i];
|
||||||
// Setup the status indicator, default to blank, we'll change it later
|
// Setup the status indicator, default to blank, we'll change it later
|
||||||
let statusIndicator = "``[";
|
let statusIndicator = "";
|
||||||
if ((leaderboardEntry.treeHeight % 1).toFixed(1) > 0) statusIndicator += "💧|";
|
if ((leaderboardEntry.treeHeight % 1).toFixed(1) > 0) statusIndicator += "``[💧]``";
|
||||||
|
|
||||||
// Get the data for this tree from 24 hours ago
|
// Get the data for this tree from 24 hours ago
|
||||||
const get24hTreeResponse = await dbfn.get24hTree(interaction.guildId, leaderboardEntry.treeName);
|
// const get24hTreeResponse = await dbfn.get24hTree(interaction.guildId, leaderboardEntry.treeName);
|
||||||
const dayAgoTree = get24hTreeResponse.data;
|
// const dayAgoTree = get24hTreeResponse.data;
|
||||||
const hist24hDifference = (leaderboardEntry.treeHeight - dayAgoTree.treeHeight).toFixed(1);
|
// const hist24hDifference = (leaderboardEntry.treeHeight - dayAgoTree.treeHeight).toFixed(1);
|
||||||
statusIndicator += `+${hist24hDifference}ft|`
|
// statusIndicator += `+${hist24hDifference}ft|`
|
||||||
|
|
||||||
// Get the 24h watering time for this tree
|
// Get the 24h watering time for this tree
|
||||||
const totalWaterTime = await functions.timeToHeight(dayAgoTree.treeHeight, leaderboardEntry.treeHeight);
|
// const totalWaterTime = await functions.timeToHeight(dayAgoTree.treeHeight, leaderboardEntry.treeHeight);
|
||||||
statusIndicator += `${totalWaterTime}]\`\``;
|
// statusIndicator += `${totalWaterTime}]\`\``;
|
||||||
|
|
||||||
// Determine if this tree is the guild's tree
|
// Determine if this tree is the guild's tree
|
||||||
if (leaderboardEntry.hasPin) {
|
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
|
// 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`;
|
// if (process.env.isDev == 'true') comparisonReplyString += `Current Height: ${leaderboardEntry.treeHeight} 24h Ago Height: ${dayAgoTree.treeHeight}\n`;
|
||||||
}
|
}
|
||||||
return comparisonReplyString;
|
return comparisonReplyString;
|
||||||
@ -398,13 +398,13 @@ const functions = {
|
|||||||
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 readyToWater = treeMessage.embeds[0].description.includes('Ready to be watered');
|
||||||
if (readyToWater) {
|
if (readyToWater) {
|
||||||
console.log("Ready to water");
|
// console.log("Ready to water");
|
||||||
this.sendReminder(guildInfo, guild);
|
this.sendReminder(guildInfo, guild);
|
||||||
this.sleep(5000).then(() => {
|
this.sleep(5000).then(() => {
|
||||||
this.checkReady(client);
|
this.checkReady(client);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("Not ready to water");
|
// console.log("Not ready to water");
|
||||||
this.sleep(5000).then(() => {
|
this.sleep(5000).then(() => {
|
||||||
this.checkReady(client);
|
this.checkReady(client);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user