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.",
"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.",
"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": {
"water": "is ready to be watered again!",

View File

@ -54,9 +54,9 @@ module.exports = {
this.watchChannelId = watchChannelId;
return this;
}
setRoles(waterRole, fruitRole) {
this.waterRoleId = waterRole.id;
if (fruitRole) this.fruitRoleId = fruitRole.id;
setRoles(waterRoleId, fruitRoleId) {
this.waterRoleId = waterRoleId;
if (fruitRoleId) this.fruitRoleId = fruitRoleId;
return this;
}
queryBuilder(query) {
@ -134,9 +134,12 @@ module.exports = {
case "setRoles":
if (this.fruitRoleId != "") {
queryParts = [
`UPDATE guild_info SET water_role_id = ${db.escape(this.waterRoleId)}, `,
`fruit_role_id = ${db.escape(this.fruitRoleId)} `,
`WHERE guild_id = ${db.escape(this.guildId)}`
`INSERT INTO guild_info (`,
`guild_id, water_role_id, fruit_role_id`,
`) 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 {
queryParts = [

View File

@ -543,7 +543,7 @@ const functions = {
const comparedRankings = await this.rankings.compare(interaction, 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 {
await interaction.update(this.builders.errorEmbed(findMessagesResponse.status));
}

View File

@ -1,30 +1,18 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const dbfn = require('../modules/dbfn.js');
const { SlashCommandBuilder } = require('discord.js');
const fn = require('../modules/functions.js');
const strings = require('../data/strings.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('rolemenu')
.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),
.setDescription('Send a self-assignable role selection menu'),
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)) {
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
guildInfo.setRoles(interaction.options.getRole('waterrole'), interaction.options.getRole('fruitrole'));
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));
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(e => console.error(e));
} 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 strings = require('../data/strings.json');
const dbfn = require('../modules/dbfn.js');
const { GuildInfo } = require('../modules/CustomClasses.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('setup')
.setDescription('Attempt automatic configuration of the bot.')
.addChannelOption(o =>
o.setName('treechannel')
.setDescription('What channel is your tree in?')
.setRequired(true))
.addChannelOption(o =>
o.setName('leaderboardchannel')
.setDescription('If your leaderboard isn\'t in the same channel, where is it?')
.setRequired(false))
.addSubcommand(sc =>
sc.setName('compare')
.setDescription('Set up the channels to be used with /compare')
.addChannelOption(o =>
o.setName('treechannel')
.setDescription('What channel is your tree in?')
.setRequired(true)
)
.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),
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
/**/
let guildInfo = {
"guildId": interaction.guildId,
"treeName": "",
"treeHeight": 0,
"treeMessageId": "",
"treeChannelId": `${interaction.options.getChannel('treechannel').id }`,
"leaderboardMessageId": "",
"leaderboardChannelId": `${interaction.options.getChannel('leaderboardchannel').id || interaction.options.getChannel('treechannel').id }`,
"reminderMessage": "",
"reminderChannelId": "",
"remindedStatus": 0,
"reminderOptIn": 0,
};
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
interaction.editReply(findMessagesResponse.status);
const subcommand = interaction.options.getSubcommand();
switch (subcommand) {
case "compare":
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));
} 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));
}
break;
case "rolemenu":
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;
}
},
};