Move role menu setup and allow everyone to send it

This commit is contained in:
Skylar Grant 2023-02-19 19:20:35 -05:00
parent f03314af80
commit fdfc2fc88a
5 changed files with 82 additions and 50 deletions

View File

@ -59,7 +59,8 @@
"missingTreeMessage": "There was a problem finding the Tree message. Please make sure the ``/tree`` and ``/top trees`` messages are this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.", "missingTreeMessage": "There was a problem finding the Tree message. Please make sure the ``/tree`` and ``/top trees`` messages are this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.",
"missingTreeChannel": "There was a problem finding the Tree channel, was it deleted? Please make sure the ``/tree`` and ``/top trees`` messages are in this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.", "missingTreeChannel": "There was a problem finding the Tree channel, was it deleted? Please make sure the ``/tree`` and ``/top trees`` messages are in this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.",
"reset": "All guild configuration information has been removed from the database.", "reset": "All guild configuration information has been removed from the database.",
"resetError": "There was a problem deleting your guild information, contact @voidf1sh#0420 for help." "resetError": "There was a problem deleting your guild information, contact @voidf1sh#0420 for help.",
"noRoleMenu": "A role menu has not been created for this guild yet. Run </setup rolemenu:0> to create a role menu."
}, },
"notifications": { "notifications": {
"water": "is ready to be watered again!", "water": "is ready to be watered again!",

View File

@ -54,9 +54,9 @@ module.exports = {
this.watchChannelId = watchChannelId; this.watchChannelId = watchChannelId;
return this; return this;
} }
setRoles(waterRole, fruitRole) { setRoles(waterRoleId, fruitRoleId) {
this.waterRoleId = waterRole.id; this.waterRoleId = waterRoleId;
if (fruitRole) this.fruitRoleId = fruitRole.id; if (fruitRoleId) this.fruitRoleId = fruitRoleId;
return this; return this;
} }
queryBuilder(query) { queryBuilder(query) {
@ -134,9 +134,12 @@ module.exports = {
case "setRoles": case "setRoles":
if (this.fruitRoleId != "") { if (this.fruitRoleId != "") {
queryParts = [ queryParts = [
`UPDATE guild_info SET water_role_id = ${db.escape(this.waterRoleId)}, `, `INSERT INTO guild_info (`,
`fruit_role_id = ${db.escape(this.fruitRoleId)} `, `guild_id, water_role_id, fruit_role_id`,
`WHERE guild_id = ${db.escape(this.guildId)}` `) VALUES (`,
`${db.escape(this.guildId)}, ${db.escape(this.waterRoleId)}, ${db.escape(this.fruitRoleId)}`,
`) ON DUPLICATE KEY UPDATE water_role_id = ${db.escape(this.waterRoleId)}, `,
`fruit_role_id = ${db.escape(this.fruitRoleId)}`
]; ];
} else { } else {
queryParts = [ queryParts = [

View File

@ -543,7 +543,7 @@ const functions = {
const comparedRankings = await this.rankings.compare(interaction, guildInfo); const comparedRankings = await this.rankings.compare(interaction, guildInfo);
const embed = this.builders.comparisonEmbed(comparedRankings, guildInfo); const embed = this.builders.comparisonEmbed(comparedRankings, guildInfo);
await interaction.update(embed).catch(err => console.error(err)); await interaction.update(embed).catch(e => console.error(e));
} else { } else {
await interaction.update(this.builders.errorEmbed(findMessagesResponse.status)); await interaction.update(this.builders.errorEmbed(findMessagesResponse.status));
} }

View File

@ -1,30 +1,18 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); const { SlashCommandBuilder } = require('discord.js');
const dbfn = require('../modules/dbfn.js');
const fn = require('../modules/functions.js'); const fn = require('../modules/functions.js');
const strings = require('../data/strings.json');
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('rolemenu') .setName('rolemenu')
.setDescription('Send a self-assignable role selection menu') .setDescription('Send a self-assignable role selection menu'),
.addRoleOption(o =>
o.setName('waterrole')
.setDescription('The role for water reminder pings')
.setRequired(true))
.addRoleOption(o =>
o.setName('fruitrole')
.setDescription('The role for fruit alert pings')
.setRequired(false))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles),
async execute(interaction) { async execute(interaction) {
await interaction.deferReply().catch(err => console.error(err)); await interaction.deferReply().catch(e => console.error(e));
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);
guildInfo.setRoles(interaction.options.getRole('waterrole'), interaction.options.getRole('fruitrole')); await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(e => console.error(e));
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 { } 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)); await interaction.editReply(fn.builders.errorEmbed(strings.status.noRoleMenu)).catch(e => console.error(e));
} }
}, },
}; };

View File

@ -2,37 +2,77 @@ const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const fn = require('../modules/functions.js'); const fn = require('../modules/functions.js');
const strings = require('../data/strings.json'); const strings = require('../data/strings.json');
const dbfn = require('../modules/dbfn.js'); const dbfn = require('../modules/dbfn.js');
const { GuildInfo } = require('../modules/CustomClasses.js');
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('setup') .setName('setup')
.setDescription('Attempt automatic configuration of the bot.') .setDescription('Attempt automatic configuration of the bot.')
.addChannelOption(o => .addSubcommand(sc =>
o.setName('treechannel') sc.setName('compare')
.setDescription('What channel is your tree in?') .setDescription('Set up the channels to be used with /compare')
.setRequired(true)) .addChannelOption(o =>
.addChannelOption(o => o.setName('treechannel')
o.setName('leaderboardchannel') .setDescription('What channel is your tree in?')
.setDescription('If your leaderboard isn\'t in the same channel, where is it?') .setRequired(true)
.setRequired(false)) )
.addChannelOption(o =>
o.setName('leaderboardchannel')
.setDescription('If your leaderboard isn\'t in the same channel, where is it?')
.setRequired(false)
)
)
.addSubcommand(sc =>
sc.setName('rolemenu')
.setDescription('Setup the roles to be used with /rolemenu')
.addRoleOption(o =>
o.setName('waterrole')
.setDescription('The role for water reminder pings')
.setRequired(true)
)
.addRoleOption(o =>
o.setName('fruitrole')
.setDescription('The role for fruit alert pings')
.setRequired(false)
)
)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator), .setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async execute(interaction) { async execute(interaction) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
/**/ const subcommand = interaction.options.getSubcommand();
let guildInfo = { switch (subcommand) {
"guildId": interaction.guildId, case "compare":
"treeName": "", if (interaction.client.guildInfos.has(interaction.guildId)) {
"treeHeight": 0, let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
"treeMessageId": "", const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
"treeChannelId": `${interaction.options.getChannel('treechannel').id }`, await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e));
"leaderboardMessageId": "", } else {
"leaderboardChannelId": `${interaction.options.getChannel('leaderboardchannel').id || interaction.options.getChannel('treechannel').id }`, let guildInfo = new GuildInfo()
"reminderMessage": "", .setId(interaction.guildId);
"reminderChannelId": "", const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
"remindedStatus": 0, await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e));
"reminderOptIn": 0, }
}; break;
const findMessagesResponse = await fn.messages.find(interaction, guildInfo); case "rolemenu":
interaction.editReply(findMessagesResponse.status); let waterRoleId = interaction.options.getRole('waterrole').id;
let fruitRoleId = interaction.options.getRole('fruitrole') ? interaction.options.getRole('fruitrole').id : undefined;
if (interaction.client.guildInfos.has(interaction.guildId)) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
guildInfo.setRoles(waterRoleId, fruitRoleId);
await dbfn.setGuildInfo(guildInfo.queryBuilder("setRoles"));
await fn.collectionBuilders.guildInfos(interaction.client);
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(e => console.error(e));
} else {
let guildInfo = new GuildInfo()
.setId(interaction.guildId);
guildInfo.setRoles(waterRoleId, fruitRoleId);
await dbfn.setGuildInfo(guildInfo.queryBuilder("setRoles"));
await fn.collectionBuilders.guildInfos(interaction.client);
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(e => console.error(e));
}
break;
default:
break;
}
}, },
}; };