Parse next water time from tree message
Some checks reported warnings
Silvanus Production Dockerization / build (pull_request) Has been cancelled
Some checks reported warnings
Silvanus Production Dockerization / build (pull_request) Has been cancelled
Doesn't do anything yet.
This commit is contained in:
parent
d268f52237
commit
8538fced37
@ -615,11 +615,16 @@ const functions = {
|
|||||||
const indices = [description.indexOf("Your tree is ") + 13, description.indexOf("ft")];
|
const indices = [description.indexOf("Your tree is ") + 13, description.indexOf("ft")];
|
||||||
const treeHeightStr = description.slice(indices[0], indices[1]);
|
const treeHeightStr = description.slice(indices[0], indices[1]);
|
||||||
const treeHeightFloat = parseFloat(treeHeightStr).toFixed(1);
|
const treeHeightFloat = parseFloat(treeHeightStr).toFixed(1);
|
||||||
|
// Grab the tree's water timestamp
|
||||||
|
const waterTimestampStr = description.match(/<t:[0-9]+:R>/g)[0];
|
||||||
|
const waterTimestamp = waterTimestampStr.match(/[0-9]+/g);
|
||||||
|
if (isDev) console.log(`Water Timestamp: ${waterTimestamp}`);
|
||||||
|
|
||||||
// Return the info gathered
|
// Return the info gathered
|
||||||
return {
|
return {
|
||||||
treeName: treeName,
|
treeName: treeName,
|
||||||
treeHeight: treeHeightFloat
|
treeHeight: treeHeightFloat,
|
||||||
|
waterTimestamp: waterTimestamp
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -696,6 +701,7 @@ const functions = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async updateHandler(message) {
|
async updateHandler(message) {
|
||||||
|
// If we don't have the entire message yet, fetch it
|
||||||
if (message.partial) {
|
if (message.partial) {
|
||||||
message = await message.fetch().catch(e => {
|
message = await message.fetch().catch(e => {
|
||||||
throw e;
|
throw e;
|
||||||
@ -706,7 +712,7 @@ const functions = {
|
|||||||
// Check and store the message types
|
// Check and store the message types
|
||||||
const isLeaderboard = this.isLeaderboard(message);
|
const isLeaderboard = this.isLeaderboard(message);
|
||||||
const isTree = this.isTree(message);
|
const isTree = this.isTree(message);
|
||||||
// Check if the message is a leaderboard
|
// Check if the message is a leaderboard and handle the update
|
||||||
if (isLeaderboard) {
|
if (isLeaderboard) {
|
||||||
if (isDev) console.log(`LU: ${message.guild.name}`);
|
if (isDev) console.log(`LU: ${message.guild.name}`);
|
||||||
let guildInfo;
|
let guildInfo;
|
||||||
@ -762,26 +768,35 @@ const functions = {
|
|||||||
const comparedRankings = await functions.rankings.compare(guildInfo);
|
const comparedRankings = await functions.rankings.compare(guildInfo);
|
||||||
const embed = functions.builders.comparisonEmbed(comparedRankings, guildInfo);
|
const embed = functions.builders.comparisonEmbed(comparedRankings, guildInfo);
|
||||||
await compareMessage.edit(embed).catch(e => console.error(e));
|
await compareMessage.edit(embed).catch(e => console.error(e));
|
||||||
} else if (isTree) {
|
} else if (isTree) { // Check if the message is a tree
|
||||||
// Check if the message is a tree
|
if (isDev) console.log(`TU: ${isTree.treeName}: ${isTree.treeHeight}ft`);
|
||||||
// if (isDev) console.log(`TU: ${isTree.treeName}: ${isTree.treeHeight}ft`);
|
|
||||||
let guildInfo;
|
let guildInfo;
|
||||||
|
// Default to not updating the database
|
||||||
let doDbUpdate = false;
|
let doDbUpdate = false;
|
||||||
|
// Check if the bot has the guildInfo for this Guild already
|
||||||
if (message.client.guildInfos.has(message.guildId)) {
|
if (message.client.guildInfos.has(message.guildId)) {
|
||||||
guildInfo = message.client.guildInfos.get(message.guildId);
|
guildInfo = message.client.guildInfos.get(message.guildId);
|
||||||
|
// If the name or height has changed, update the guildInfo and flag to run a database update
|
||||||
if ((guildInfo.treeName != isTree.treeName) || (guildInfo.treeHeight != isTree.treeHeight)) {
|
if ((guildInfo.treeName != isTree.treeName) || (guildInfo.treeHeight != isTree.treeHeight)) {
|
||||||
guildInfo.setTreeInfo(isTree.treeName, isTree.treeHeight, message.channel.id, message.id);
|
guildInfo.setTreeInfo(isTree.treeName, isTree.treeHeight, message.channel.id, message.id);
|
||||||
doDbUpdate = true;
|
doDbUpdate = true;
|
||||||
}
|
}
|
||||||
} else {
|
// If the waterTimestamp has changed, update the database
|
||||||
|
// TODO... lost motivation
|
||||||
|
} else { // If the bot doesn't have a guildInfo for the Guild, we will create one for it and flag a database update
|
||||||
guildInfo = new GuildInfo().setIds(message.guildId, message.guild.ownerId)
|
guildInfo = new GuildInfo().setIds(message.guildId, message.guild.ownerId)
|
||||||
.setTreeInfo(isTree.treeName, isTree.treeHeight, message.channel.id, message.id);
|
.setTreeInfo(isTree.treeName, isTree.treeHeight, message.channel.id, message.id);
|
||||||
doDbUpdate = true;
|
doDbUpdate = true;
|
||||||
}
|
}
|
||||||
|
// If the database update flag is set, update the database and rebuild the guildInfo collection
|
||||||
|
// TODO: This should likely only update the relevant guildInfo in the future.
|
||||||
|
// Actually, rebuilding the collection should be unnecessary, since it's already been updated.
|
||||||
if (doDbUpdate) {
|
if (doDbUpdate) {
|
||||||
const query = guildInfo.queryBuilder("setTreeInfo");
|
const query = guildInfo.queryBuilder("setTreeInfo");
|
||||||
await dbfn.setGuildInfo(query);
|
await dbfn.setGuildInfo(query);
|
||||||
await functions.collectionBuilders.guildInfos(message.client);
|
// I've commented this out to see if it breaks anything.
|
||||||
|
// Rebuilding shouldn't be necessary and is a waste of resources.
|
||||||
|
// await functions.collectionBuilders.guildInfos(message.client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user