2024-09-25 23:07:02 +01:00
|
|
|
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
|
|
|
|
const ServerSettings = require("../../models/ServerSettings");
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName("setup")
|
|
|
|
.setDescription("Configure server settings for verification.")
|
|
|
|
.addChannelOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("logchannel")
|
|
|
|
.setDescription("Select the log channel for logging actions.")
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
.addChannelOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("generalchannel")
|
|
|
|
.setDescription("Select the general channel for join messages.")
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
.addChannelOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("verificationchannel")
|
|
|
|
.setDescription("Select the verification channel where users verify.")
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
.addRoleOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("verifiedrole")
|
|
|
|
.setDescription("Select the Verified role for verified users.")
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("emaildomains")
|
|
|
|
.setDescription("Comma-separated list of allowed email domains.")
|
|
|
|
.setRequired(true)
|
2024-10-29 00:04:55 +00:00
|
|
|
)
|
|
|
|
.addChannelOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("actionitemschannel")
|
|
|
|
.setDescription(
|
|
|
|
"Select the allowed channel for action items. (Optional)"
|
|
|
|
)
|
|
|
|
.setRequired(false)
|
2024-10-29 09:12:44 +00:00
|
|
|
)
|
|
|
|
.addChannelOption((option) =>
|
|
|
|
option
|
|
|
|
.setName("actionitemstargetchannel")
|
|
|
|
.setDescription(
|
|
|
|
"Select the target channel where action items are going to be sent. (Optional)"
|
|
|
|
)
|
|
|
|
.setRequired(false)
|
2024-09-25 23:07:02 +01:00
|
|
|
),
|
|
|
|
|
|
|
|
async execute(interaction) {
|
|
|
|
// Check if the user has admin permissions
|
|
|
|
if (
|
|
|
|
!interaction.member.permissions.has(PermissionFlagsBits.Administrator)
|
|
|
|
) {
|
|
|
|
return interaction.reply({
|
|
|
|
content: "You do not have permission to use this command.",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const logChannel = interaction.options.getChannel("logchannel");
|
|
|
|
const generalChannel = interaction.options.getChannel("generalchannel");
|
|
|
|
const verificationChannel = interaction.options.getChannel(
|
|
|
|
"verificationchannel"
|
|
|
|
);
|
|
|
|
const verifiedRole = interaction.options.getRole("verifiedrole");
|
|
|
|
const emailDomains = interaction.options
|
|
|
|
.getString("emaildomains")
|
2024-10-29 00:10:54 +00:00
|
|
|
.split(",")
|
|
|
|
.map((domain) => domain.trim());
|
2024-10-29 00:04:55 +00:00
|
|
|
const actionitemschannel =
|
|
|
|
interaction.options.getChannel("actionitemschannel");
|
2024-10-29 09:12:44 +00:00
|
|
|
const actionitemstargetchannel = interaction.options.getChannel(
|
|
|
|
"actionitemstargetchannel"
|
|
|
|
);
|
2024-09-25 23:07:02 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
// Store the channel IDs instead of names
|
|
|
|
await ServerSettings.findOneAndUpdate(
|
|
|
|
{ guildId: interaction.guild.id },
|
|
|
|
{
|
|
|
|
guildId: interaction.guild.id,
|
2024-10-29 00:04:55 +00:00
|
|
|
logChannelId: logChannel.id,
|
2024-09-25 23:07:02 +01:00
|
|
|
verifiedRoleName: verifiedRole.name,
|
2024-10-29 00:04:55 +00:00
|
|
|
verificationChannelId: verificationChannel.id,
|
|
|
|
generalChannelId: generalChannel.id,
|
2024-09-25 23:07:02 +01:00
|
|
|
emailDomains: emailDomains,
|
2024-10-29 00:04:55 +00:00
|
|
|
actionItemsChannelId: actionitemschannel
|
|
|
|
? actionitemschannel.id
|
|
|
|
: null,
|
2024-10-29 09:12:44 +00:00
|
|
|
actionItemsTargetChannelId: actionitemstargetchannel
|
|
|
|
? actionitemstargetchannel.id
|
|
|
|
: null,
|
2024-09-25 23:07:02 +01:00
|
|
|
},
|
|
|
|
{ upsert: true, new: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
interaction.reply({
|
|
|
|
content: `Server settings have been updated successfully!\n
|
|
|
|
**Log Channel**: <#${logChannel.id}>\n
|
|
|
|
**General Channel**: <#${generalChannel.id}>\n
|
|
|
|
**Verification Channel**: <#${verificationChannel.id}>\n
|
|
|
|
**Verified Role**: ${verifiedRole.name}\n
|
2024-10-29 00:04:55 +00:00
|
|
|
**Allowed Email Domains**: ${emailDomains.join(", ")}\n
|
|
|
|
**Action Item Channel**: ${
|
|
|
|
actionitemschannel ? `<#${actionitemschannel.id}>` : "None"
|
2024-10-29 09:12:44 +00:00
|
|
|
}\n
|
|
|
|
**Action Item Target Channel**: ${
|
|
|
|
actionitemstargetchannel
|
|
|
|
? `<#${actionitemstargetchannel.id}>`
|
|
|
|
: "None"
|
|
|
|
}
|
|
|
|
`,
|
2024-09-25 23:07:02 +01:00
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error updating server settings:", error);
|
|
|
|
interaction.reply({
|
|
|
|
content: "There was an error updating the server settings.",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|