action items: make it that the channel is grabbed from the db, and add action items channel to the server settings and setup command

This commit is contained in:
Ayden Jahola 2024-10-29 00:04:55 +00:00
parent 7e74d3e4e6
commit 59b3c8507f
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742
3 changed files with 39 additions and 8 deletions

View file

@ -1,4 +1,5 @@
const { SlashCommandBuilder } = require("discord.js"); const { SlashCommandBuilder } = require("discord.js");
const ServerSettings = require("../../models/ServerSettings");
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -16,11 +17,23 @@ module.exports = {
), ),
async execute(interaction) { async execute(interaction) {
// Check if the command is used in the allowed channel const serverSettings = await ServerSettings.findOne({
const allowedChannelId = "1299134735330836521"; guildId: interaction.guild.id,
if (interaction.channelId !== allowedChannelId) { });
if (!serverSettings) {
return interaction.reply({ return interaction.reply({
content: `This command can only be used in the designated channel.`, content:
"Server settings are not configured. Please run the setup command.",
ephemeral: true,
});
}
const actionItemChannelId = serverSettings.actionItemsChannelId;
if (interaction.channelId !== actionItemChannelId) {
return interaction.reply({
content: `This command can only be used in the <#${actionItemChannelId}> channel.`,
ephemeral: true, ephemeral: true,
}); });
} }

View file

@ -34,6 +34,14 @@ module.exports = {
.setName("emaildomains") .setName("emaildomains")
.setDescription("Comma-separated list of allowed email domains.") .setDescription("Comma-separated list of allowed email domains.")
.setRequired(true) .setRequired(true)
)
.addChannelOption((option) =>
option
.setName("actionitemschannel")
.setDescription(
"Select the allowed channel for action items. (Optional)"
)
.setRequired(false)
), ),
async execute(interaction) { async execute(interaction) {
@ -56,6 +64,8 @@ module.exports = {
const emailDomains = interaction.options const emailDomains = interaction.options
.getString("emaildomains") .getString("emaildomains")
.split(","); .split(",");
const actionitemschannel =
interaction.options.getChannel("actionitemschannel");
try { try {
// Store the channel IDs instead of names // Store the channel IDs instead of names
@ -63,11 +73,14 @@ module.exports = {
{ guildId: interaction.guild.id }, { guildId: interaction.guild.id },
{ {
guildId: interaction.guild.id, guildId: interaction.guild.id,
logChannelId: logChannel.id, // Store log channel ID logChannelId: logChannel.id,
verifiedRoleName: verifiedRole.name, verifiedRoleName: verifiedRole.name,
verificationChannelId: verificationChannel.id, // Store verification channel ID verificationChannelId: verificationChannel.id,
generalChannelId: generalChannel.id, // Store general channel ID generalChannelId: generalChannel.id,
emailDomains: emailDomains, emailDomains: emailDomains,
actionItemsChannelId: actionitemschannel
? actionitemschannel.id
: null,
}, },
{ upsert: true, new: true } { upsert: true, new: true }
); );
@ -78,7 +91,10 @@ module.exports = {
**General Channel**: <#${generalChannel.id}>\n **General Channel**: <#${generalChannel.id}>\n
**Verification Channel**: <#${verificationChannel.id}>\n **Verification Channel**: <#${verificationChannel.id}>\n
**Verified Role**: ${verifiedRole.name}\n **Verified Role**: ${verifiedRole.name}\n
**Allowed Email Domains**: ${emailDomains.join(", ")}`, **Allowed Email Domains**: ${emailDomains.join(", ")}\n
**Action Item Channel**: ${
actionitemschannel ? `<#${actionitemschannel.id}>` : "None"
}`,
ephemeral: true, ephemeral: true,
}); });
} catch (error) { } catch (error) {

View file

@ -7,7 +7,9 @@ const ServerSettingsSchema = new mongoose.Schema({
verificationChannelId: { type: String, required: false }, verificationChannelId: { type: String, required: false },
generalChannelId: { type: String, required: false }, generalChannelId: { type: String, required: false },
emailDomains: { type: [String], required: false }, emailDomains: { type: [String], required: false },
actionItemsChannelId: { type: String, required: false },
}); });
const ServerSettings = mongoose.model("ServerSettings", ServerSettingsSchema); const ServerSettings = mongoose.model("ServerSettings", ServerSettingsSchema);
module.exports = ServerSettings; module.exports = ServerSettings;