Fix /setup compare

This commit is contained in:
Skylar Grant 2023-02-20 15:14:57 -05:00
parent a70b27b112
commit e7a76eee65
2 changed files with 29 additions and 17 deletions

View File

@ -39,12 +39,12 @@ module.exports = {
return this;
}
setTreeMessage(messageId, channelId) {
this.treeMessageId = messageId;
this.treeMessageId = messageId ? messageId : this.treeMessageId;
this.treeChannelId = channelId;
return this;
}
setLeaderboardMessage(messageId, channelId) {
this.leaderboardMessageId = messageId;
this.leaderboardMessageId = messageId ? messageId : this.leaderboardMessageId;
this.leaderboardChannelId = channelId;
return this;
}
@ -122,7 +122,7 @@ module.exports = {
case "setTreeMessage":
queryParts = [
`UPDATE guild_info SET tree_message_id = ${db.escape(this.treeMessageId)}, `,
`tree_channel_id = ${db.escape(this.treeChannelId)}, `,
`tree_channel_id = ${db.escape(this.treeChannelId)} `,
`WHERE guild_id = ${db.escape(this.guildId)}`
];
return queryParts.join('');
@ -130,7 +130,7 @@ module.exports = {
case "setLeaderboardMessage":
queryParts = [
`UPDATE guild_info SET leaderboard_message_id = ${db.escape(this.leaderboardMessageId)}, `,
`leaderboard_channel_id = ${db.escape(this.leaderboardChannelId)}, `,
`leaderboard_channel_id = ${db.escape(this.leaderboardChannelId)} `,
`WHERE guild_id = ${db.escape(this.guildId)}`
];
return queryParts.join('');

View File

@ -18,8 +18,8 @@ module.exports = {
)
.addChannelOption(o =>
o.setName('leaderboardchannel')
.setDescription('If your leaderboard isn\'t in the same channel, where is it?')
.setRequired(false)
.setDescription('What channel is your leaderboard in?')
.setRequired(true)
)
)
.addSubcommand(sc =>
@ -54,15 +54,27 @@ module.exports = {
const subcommand = interaction.options.getSubcommand();
switch (subcommand) {
case "compare":
const treeChannel = interaction.options.getChannel('treechannel');
const leaderboardChannel = interaction.options.getChannel('leaderboardchannel');
if (interaction.client.guildInfos.has(interaction.guildId)) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e));
guildInfo.setTreeMessage(undefined, treeChannel.id);
guildInfo.setLeaderboardMessage(undefined, leaderboardChannel.id);
// Update the database
await dbfn.setGuildInfo(guildInfo.queryBuilder("setTreeMessage")).catch(e => console.error(e));
await dbfn.setGuildInfo(guildInfo.queryBuilder("setLeaderboardMessage")).catch(e => console.error(e));
const reply = `Tree Channel: <#${treeChannel.id}> | Leaderboard Channel: <#${leaderboardChannel.id}>`;
await interaction.editReply(fn.builders.embed(reply)).catch(e => console.error(e));
} else {
let guildInfo = new GuildInfo()
.setId(interaction.guildId);
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e));
.setId(interaction.guildId)
.setTreeMessage(undefined, treeChannel.id)
.setLeaderboardMessage(undefined, leaderboardChannel.id);
// Update the database
await dbfn.setGuildInfo(guildInfo.queryBuilder("setTreeMessage")).catch(e => console.error(e));
await dbfn.setGuildInfo(guildInfo.queryBuilder("setLeaderboardMessage")).catch(e => console.error(e));
const reply = `Tree Channel: <#${treeChannel.id}> | Leaderboard Channel: <#${leaderboardChannel.id}>`;
await interaction.editReply(fn.builders.embed(reply)).catch(e => console.error(e));
}
break;
case "rolemenu":