123 lines
4.3 KiB
JavaScript
123 lines
4.3 KiB
JavaScript
const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
|
|
|
|
module.exports = {
|
|
name: 'setup-adminlogs',
|
|
description: 'Configure admin moderation logging settings',
|
|
enabled: true,
|
|
builder: new SlashCommandBuilder()
|
|
.setName('setup-adminlogs')
|
|
.setDescription('Configure admin moderation logging settings')
|
|
.addChannelOption(option =>
|
|
option.setName('channel')
|
|
.setDescription('Channel to send admin logs to')
|
|
.setRequired(false))
|
|
.addBooleanOption(option =>
|
|
option.setName('enabled')
|
|
.setDescription('Enable or disable admin logging')
|
|
.setRequired(false))
|
|
.addBooleanOption(option =>
|
|
option.setName('kick_logs')
|
|
.setDescription('Log kick actions')
|
|
.setRequired(false))
|
|
.addBooleanOption(option =>
|
|
option.setName('ban_logs')
|
|
.setDescription('Log ban actions')
|
|
.setRequired(false))
|
|
.addBooleanOption(option =>
|
|
option.setName('timeout_logs')
|
|
.setDescription('Log timeout actions')
|
|
.setRequired(false)),
|
|
async execute(interaction) {
|
|
// Check if user has administrator permissions
|
|
if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) {
|
|
return interaction.reply({
|
|
content: 'You need Administrator permissions to configure admin logs.',
|
|
flags: 64
|
|
});
|
|
}
|
|
|
|
const channel = interaction.options.getChannel('channel');
|
|
const enabled = interaction.options.getBoolean('enabled');
|
|
const kickLogs = interaction.options.getBoolean('kick_logs');
|
|
const banLogs = interaction.options.getBoolean('ban_logs');
|
|
const timeoutLogs = interaction.options.getBoolean('timeout_logs');
|
|
|
|
try {
|
|
// Get current settings
|
|
const response = await fetch(`${process.env.BACKEND_BASE || 'http://localhost:3001'}/api/servers/${interaction.guildId}/admin-logs-settings`);
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch current settings');
|
|
}
|
|
const currentSettings = await response.json();
|
|
|
|
// Update settings
|
|
const updatedSettings = { ...currentSettings };
|
|
|
|
if (enabled !== null) {
|
|
updatedSettings.enabled = enabled;
|
|
}
|
|
|
|
if (channel) {
|
|
// Check if it's a text channel
|
|
if (channel.type !== 0) { // 0 = GUILD_TEXT
|
|
return interaction.reply({
|
|
content: 'Please select a text channel for admin logs.',
|
|
flags: 64
|
|
});
|
|
}
|
|
updatedSettings.channelId = channel.id;
|
|
}
|
|
|
|
// Update command-specific settings
|
|
updatedSettings.commands = { ...updatedSettings.commands };
|
|
if (kickLogs !== null) {
|
|
updatedSettings.commands.kick = kickLogs;
|
|
}
|
|
if (banLogs !== null) {
|
|
updatedSettings.commands.ban = banLogs;
|
|
}
|
|
if (timeoutLogs !== null) {
|
|
updatedSettings.commands.timeout = timeoutLogs;
|
|
}
|
|
|
|
// Save settings
|
|
const saveResponse = await fetch(`${process.env.BACKEND_BASE || 'http://localhost:3001'}/api/servers/${interaction.guildId}/admin-logs-settings`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(updatedSettings)
|
|
});
|
|
|
|
if (!saveResponse.ok) {
|
|
throw new Error('Failed to save settings');
|
|
}
|
|
|
|
const result = await saveResponse.json();
|
|
|
|
// Create response message
|
|
let responseMessage = 'Admin logs settings updated!\n\n';
|
|
responseMessage += `**Enabled:** ${result.settings.enabled ? 'Yes' : 'No'}\n`;
|
|
if (result.settings.channelId) {
|
|
responseMessage += `**Channel:** <#${result.settings.channelId}>\n`;
|
|
} else {
|
|
responseMessage += `**Channel:** Not set\n`;
|
|
}
|
|
responseMessage += `**Kick Logs:** ${result.settings.commands.kick ? 'Enabled' : 'Disabled'}\n`;
|
|
responseMessage += `**Ban Logs:** ${result.settings.commands.ban ? 'Enabled' : 'Disabled'}\n`;
|
|
responseMessage += `**Timeout Logs:** ${result.settings.commands.timeout ? 'Enabled' : 'Disabled'}`;
|
|
|
|
await interaction.reply({
|
|
content: responseMessage,
|
|
flags: 64
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('Error configuring admin logs:', error);
|
|
await interaction.reply({
|
|
content: 'An error occurred while configuring admin logs. Please try again later.',
|
|
flags: 64
|
|
});
|
|
}
|
|
}
|
|
}; |