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

View File

@ -18,8 +18,8 @@ module.exports = {
) )
.addChannelOption(o => .addChannelOption(o =>
o.setName('leaderboardchannel') o.setName('leaderboardchannel')
.setDescription('If your leaderboard isn\'t in the same channel, where is it?') .setDescription('What channel is your leaderboard in?')
.setRequired(false) .setRequired(true)
) )
) )
.addSubcommand(sc => .addSubcommand(sc =>
@ -41,12 +41,12 @@ module.exports = {
.setDescription('View your server\'s configuration')) .setDescription('View your server\'s configuration'))
.addSubcommand(sc => .addSubcommand(sc =>
sc.setName('reset') sc.setName('reset')
.setDescription('Remove all server configuration from the database') .setDescription('Remove all server configuration from the database')
.addBooleanOption(o => .addBooleanOption(o =>
o.setName('confirm') o.setName('confirm')
.setDescription('WARNING THIS IS IRREVERSIBLE') .setDescription('WARNING THIS IS IRREVERSIBLE')
.setRequired(true) .setRequired(true)
) )
) )
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator), .setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async execute(interaction) { async execute(interaction) {
@ -54,15 +54,27 @@ module.exports = {
const subcommand = interaction.options.getSubcommand(); const subcommand = interaction.options.getSubcommand();
switch (subcommand) { switch (subcommand) {
case "compare": case "compare":
const treeChannel = interaction.options.getChannel('treechannel');
const leaderboardChannel = interaction.options.getChannel('leaderboardchannel');
if (interaction.client.guildInfos.has(interaction.guildId)) { if (interaction.client.guildInfos.has(interaction.guildId)) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId); let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
const findMessagesResponse = await fn.messages.find(interaction, guildInfo); guildInfo.setTreeMessage(undefined, treeChannel.id);
await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e)); 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 { } else {
let guildInfo = new GuildInfo() let guildInfo = new GuildInfo()
.setId(interaction.guildId); .setId(interaction.guildId)
const findMessagesResponse = await fn.messages.find(interaction, guildInfo); .setTreeMessage(undefined, treeChannel.id)
await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e)); .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; break;
case "rolemenu": case "rolemenu":