Fixes, ready for testing

This commit is contained in:
Skylar Grant 2023-02-12 16:00:04 -05:00
parent d8e7ec2c1a
commit e6aeb685ee
5 changed files with 24 additions and 6 deletions

View File

@ -72,10 +72,12 @@ client.on('interactionCreate', async interaction => {
}
break;
case 'waterpingrole':
await interaction.reply(fn.buttonHandlers.waterPing(interaction)).catch(err => console.error(err));
const waterPingStatus = await fn.buttonHandlers.waterPing(interaction);
await interaction.reply(waterPingStatus).catch(err => console.error(err));
break;
case 'fruitpingrole':
await interaction.reply(fn.buttonHandlers.fruitPing(interaction)).catch(err => console.error(err));
const fruitPingStatus = await fn.buttonHandlers.fruitPing(interaction);
await interaction.reply(fruitPingStatus).catch(err => console.error(err));
break;
default:
break;

View File

@ -57,6 +57,7 @@ module.exports = {
setRoles(waterRoleId, fruitRoleId) {
this.waterRoleId = waterRoleId;
if (fruitRoleId) this.fruitRoleId = fruitRoleId;
return this;
}
queryBuilder(query) {
let queryParts = [];
@ -128,7 +129,7 @@ module.exports = {
case "setRoles":
queryParts = [
`UPDATE guild_info SET water_role_id = ${db.escape(this.waterRoleId)}, `,
`fruit_role_id = ${db.escape(this.fruitRoleId)}, `,
`fruit_role_id = ${db.escape(this.fruitRoleId)} `,
`WHERE guild_id = ${db.escape(this.guildId)}`
];
return queryParts.join('');

View File

@ -68,8 +68,8 @@ module.exports = {
.setHeight(row.tree_height)
.setTreeMessage(row.tree_message_id, row.tree_channel_id)
.setLeaderboardMessage(row.leaderboard_message_id, row.leaderboard_channel_id)
.setReminders(row.water_message, row.fruit_message, row.reminder_channel_id, row.watch_channel_id);
.setReminders(row.water_message, row.fruit_message, row.reminder_channel_id, row.watch_channel_id)
.setRoles(row.water_role_id, row.fruit_role_id);
db.end();
resolve(guildInfo);
});
@ -112,6 +112,7 @@ module.exports = {
.setTreeMessage(row.tree_message_id, row.tree_channel_id)
.setLeaderboardMessage(row.leaderboard_message_id, row.leaderboard_channel_id)
.setReminders(row.water_message, row.fruit_message, row.reminder_channel_id, row.watch_channel_id)
.setRoles(row.water_role_id, row.fruit_role_id)
);
}
@ -134,7 +135,7 @@ module.exports = {
return new Promise((resolve, reject) => {
db.query(query, (err, res) => {
if (err) {
console.error(err);
console.error(err + "\n" + query);
reject("Error setting the guild info: " + err.message);
db.end();
return;

View File

@ -507,6 +507,17 @@ const functions = {
}
}
},
roles: {
async fetchRole(guild, roleId) {
return await guild.roles.fetch(roleId).catch(err => console.error("Error fetching the role: " + err + "\n" + roleId));
},
async giveRole(member, role) {
await member.roles.add(role).catch(err => console.error("Error giving the role: " + err + "\n" + JSON.stringify(role)));
},
async takeRole(member, role) {
await member.roles.remove(role).catch(err => console.error("Error taking the role: " + err + "\n" + JSON.stringify(role)));
}
},
async refresh(interaction) {
// const getGuildInfoResponse = await dbfn.getGuildInfo(interaction.guildId);
// let guildInfo = getGuildInfoResponse.data;

View File

@ -1,4 +1,5 @@
const { SlashCommandBuilder } = require('discord.js');
const dbfn = require('../modules/dbfn.js');
const fn = require('../modules/functions.js');
module.exports = {
@ -18,6 +19,8 @@ module.exports = {
if (interaction.client.guildInfos.has(interaction.guildId)) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
guildInfo.setRoles(interaction.options.getRole('waterrole').id, interaction.options.getRole('fruitrole').id);
await dbfn.setGuildInfo(guildInfo.queryBuilder("setRoles"));
await fn.collectionBuilders.guildInfos(interaction.client);
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(err => console.error(err));
} else {
await interaction.editReply(fn.builders.errorEmbed("No information is known about your server yet, please run /setup or /compare")).catch(err => console.error(err));