Testing new tree update detection
This commit is contained in:
parent
3eaa7db561
commit
dbd66c248c
@ -70,5 +70,8 @@
|
|||||||
"water": "is ready to be watered again!",
|
"water": "is ready to be watered again!",
|
||||||
"fruit": "Fruit is appearing!"
|
"fruit": "Fruit is appearing!"
|
||||||
},
|
},
|
||||||
|
"ids": {
|
||||||
|
"growATree": "972637072991068220"
|
||||||
|
},
|
||||||
"temp": {}
|
"temp": {}
|
||||||
}
|
}
|
5
main.js
5
main.js
@ -86,6 +86,11 @@ client.on('interactionCreate', async interaction => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on('messageUpdate', async message => {
|
||||||
|
await fn.sleep(50);
|
||||||
|
await fn.messages.updateHandler(message);
|
||||||
|
});
|
||||||
|
|
||||||
async function checkRateLimits(hi) {
|
async function checkRateLimits(hi) {
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
|
@ -153,7 +153,17 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
return queryParts.join('');
|
return queryParts.join('');
|
||||||
break;
|
break;
|
||||||
default:
|
case "setTreeInfo":
|
||||||
|
queryParts = [
|
||||||
|
`INSERT INTO guild_info (`,
|
||||||
|
`guild_id, tree_name, tree_height`,
|
||||||
|
`) VALUES (`,
|
||||||
|
`${db.escape(this.guildId)}, ${db.escape(this.treeName)}, ${db.escape(this.treeHeight)}`,
|
||||||
|
`) ON DUPLICATE KEY UPDATE tree_name = ${db.escape(this.treeName)}, `,
|
||||||
|
`tree_height = ${db.escape(this.treeHeight)}`
|
||||||
|
];
|
||||||
|
return queryParts.join('');
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,6 @@ const functions = {
|
|||||||
},
|
},
|
||||||
tree: {
|
tree: {
|
||||||
parse(interaction, guildInfo) {
|
parse(interaction, guildInfo) {
|
||||||
let input;
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (guildInfo == undefined) {
|
if (guildInfo == undefined) {
|
||||||
reject(`The guild entry hasn't been created yet. [${interaction.guildId || interaction.commandGuildId}]`);
|
reject(`The guild entry hasn't been created yet. [${interaction.guildId || interaction.commandGuildId}]`);
|
||||||
@ -337,6 +336,7 @@ const functions = {
|
|||||||
reject("This doesn't appear to be a valid ``/tree`` message.");
|
reject("This doesn't appear to be a valid ``/tree`` message.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let input;
|
||||||
input = m.embeds[0].data.description;
|
input = m.embeds[0].data.description;
|
||||||
let treeName = m.embeds[0].data.title;
|
let treeName = m.embeds[0].data.title;
|
||||||
let lines = input.split('\n');
|
let lines = input.split('\n');
|
||||||
@ -493,12 +493,61 @@ const functions = {
|
|||||||
},
|
},
|
||||||
isTree(message) {
|
isTree(message) {
|
||||||
if (message.embeds.length > 0) {
|
if (message.embeds.length > 0) {
|
||||||
return message.embeds[0].data.description.includes("Your tree is");
|
// Grab the description and title
|
||||||
|
const {description, title} = message.embeds[0].data;
|
||||||
|
// Make sure it's a tree message
|
||||||
|
if (description.includes("Your tree is")) {
|
||||||
|
// Grab the name
|
||||||
|
const treeName = title;
|
||||||
|
// Grab the tree's height
|
||||||
|
const indices = [description.indexOf("Your tree is ") + 13, description.indexOf("ft")];
|
||||||
|
const treeHeightStr = description.slice(indices[0], indices[1]);
|
||||||
|
const treeHeightFloat = parseFloat(treeHeightStr).toFixed(1);
|
||||||
|
|
||||||
|
// Return the info gathered
|
||||||
|
return {
|
||||||
|
treeName: treeName,
|
||||||
|
treeHeight: treeHeightFloat
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isLeaderboard(message) {
|
isLeaderboard(message) {
|
||||||
if (message.embeds.length > 0) {
|
if (message.embeds.length > 0) {
|
||||||
return message.embeds[0].data.title == "Tallest Trees";
|
return message.embeds[0].data.title == "Tallest Trees";
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async updateHandler(message) {
|
||||||
|
if (message.partial) {
|
||||||
|
message = await message.fetch();
|
||||||
|
}
|
||||||
|
// Make sure the message is from Grow A Tree
|
||||||
|
if (message.author.id != strings.ids.growATree) return;
|
||||||
|
// Check and store the message types
|
||||||
|
const isLeaderboard = this.isLeaderboard(message);
|
||||||
|
const isTree = this.isTree(message);
|
||||||
|
// Check if the message is a leaderboard
|
||||||
|
if (isLeaderboard) {
|
||||||
|
// Need to actually handle this later
|
||||||
|
// console.log("I've seen a leaderboard update.");
|
||||||
|
} else if (isTree) { // Check if the message is a tree
|
||||||
|
// console.log(`I've seen a tree update: ${isTree.treeName}: ${isTree.treeHeight}ft`);
|
||||||
|
let guildInfo;
|
||||||
|
if (message.client.guildInfos.has(message.guildId)) {
|
||||||
|
guildInfo = message.client.guildInfos.get(message.guildId);
|
||||||
|
guildInfo.setName(isTree.treeName)
|
||||||
|
.setHeight(isTree.treeHeight);
|
||||||
|
} else {
|
||||||
|
guildInfo = new GuildInfo().setId(message.guildId)
|
||||||
|
.setName(isTree.treeName)
|
||||||
|
.setHeight(isTree.treeHeight);
|
||||||
|
}
|
||||||
|
const query = guildInfo.queryBuilder("setTreeInfo");
|
||||||
|
await dbfn.setGuildInfo(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user