async function promptForEditOptions(interaction, ruleId) { const rule = await interaction.guild.autoModerationRules.fetch(ruleId).catch(async err => { console.log(err); await utils.editOrReply(interaction, { embeds: [embed.error({ content: 'An error occurred while fetching the AutoMod rule.' })] }); }); if (!rule) return; let options = []; switch (rule.triggerType) { case 1: // Keyword Rule options = [ { label: 'Edit Timeout', value: 'edit-timeout' }, { label: 'Edit Log Channel', value: 'edit-log-channel' }, { label: 'Edit Keyword', value: 'edit-keyword' } ]; break; case 5: // Mention Spam Rule options = [ { label: 'Edit Timeout', value: 'edit-timeout' }, { label: 'Edit Log Channel', value: 'edit-log-channel' }, { label: 'Edit Mention Limit', value: 'edit-mention-limit' } ]; break; case 4: // Flagged Words Rule options = [ { label: 'Edit Log Channel', value: 'edit-log-channel' } ]; break; case 3: // Spam Messages Rule options = [ { label: 'Edit Log Channel', value: 'edit-log-channel' } ]; break; } const editOptionsEmbed = embed.infos({ content: 'Please select the parameter you want to edit.' }); const selectMenu = new StringSelectMenuBuilder() .setCustomId('select-edit-option') .setPlaceholder('Select an option') .addOptions(options); const actionRow = new ActionRowBuilder().addComponents(selectMenu); await utils.editOrReply(interaction, { embeds: [editOptionsEmbed], components: [actionRow] }); const filter = i => i.customId === 'select-edit-option' && i.user.id === interaction.user.id; const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async i => { const selectedOption = i.values[0]; await i.deferUpdate(); switch (selectedOption) { case 'edit-timeout': await promptForTimeoutEdit(interaction, rule); break; case 'edit-log-channel': await promptForLogChannelEdit(interaction, rule); break; case 'edit-keyword': await promptForKeywordEdit(interaction, rule); break; case 'edit-mention-limit': await promptForMentionLimitEdit(interaction, rule); break; } }); } async function promptForTimeoutEdit(interaction, rule) { const timeoutEmbed = embed.infos({ content: 'Please select the new timeout duration or keep the current one.' }); const timeoutSelectMenu = new StringSelectMenuBuilder() .setCustomId('select-new-timeout') .setPlaceholder('Select a new timeout duration') .addOptions([ { label: 'Keep current timeout', value: 'keep' }, { label: 'No timeout', value: '0' }, { label: '60 seconds', value: '60' }, { label: '5 minutes', value: '300' }, { label: '10 minutes', value: '600' }, { label: '1 hour', value: '3600' }, { label: '1 day', value: '86400' }, { label: '1 week', value: '604800' } ]); const actionRow = new ActionRowBuilder().addComponents(timeoutSelectMenu); await utils.editOrReply(interaction, { embeds: [timeoutEmbed], components: [actionRow] }); const filter = i => i.customId === 'select-new-timeout' && i.user.id === interaction.user.id; const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async i => { const newTimeout = i.values[0]; await i.deferUpdate(); if (newTimeout !== 'keep') { await rule.edit({ actions: rule.actions.map(action => action.type === AutoModerationActionType.Timeout ? { ...action, metadata: { durationSeconds: parseInt(newTimeout, 10) } } : action ) }); } await utils.editOrReply(interaction, { embeds: [embed.success({ content: 'Timeout successfully updated.' })] }); }); } async function promptForLogChannelEdit(interaction, rule) { const logChannelEmbed = embed.infos({ content: 'Please select a new log channel or keep the current one.' }); const channelSelectMenu = new StringSelectMenuBuilder() .setCustomId('select-new-log-channel') .setPlaceholder('Select a new log channel') .addOptions([ { label: 'Keep current log channel', value: 'keep' }, ...interaction.guild.channels.cache .filter(channel => channel.type === ChannelType.GuildText) .map(channel => ({ label: channel.name, value: channel.id })) ]); const actionRow = new ActionRowBuilder().addComponents(channelSelectMenu); await utils.editOrReply(interaction, { embeds: [logChannelEmbed], components: [actionRow] }); const filter = i => i.customId === 'select-new-log-channel' && i.user.id === interaction.user.id; const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async i => { const newLogChannel = i.values[0]; await i.deferUpdate(); if (newLogChannel !== 'keep') { await rule.edit({ actions: rule.actions.map(action => action.type === AutoModerationActionType.SendAlertMessage ? { ...action, metadata: { channel: newLogChannel } } : action ) }); } await utils.editOrReply(interaction, { embeds: [embed.success({ content: 'Log channel successfully updated.' })] }); }); } async function promptForKeywordEdit(interaction, rule) { const keywordEmbed = embed.infos({ content: 'Please enter the new keyword or keep the current one.' }); await utils.editOrReply(interaction, { embeds: [keywordEmbed], components: [] }); const filter = response => response.author.id === interaction.user.id; const collected = await interaction.channel.awaitMessages({ filter, max: 1, time: 60000, errors: ['time'] }).catch(() => null); if (collected && collected.first()) { const newKeyword = collected.first().content; if (newKeyword !== 'keep') { await rule.edit({ triggerMetadata: { keywordFilter: [newKeyword] } }); } await utils.editOrReply(interaction, { embeds: [embed.success({ content: 'Keyword successfully updated.' })] }); } else { await utils.editOrReply(interaction, { embeds: [embed.error({ content: 'No input received within the time limit.' })] }); } } async function promptForMentionLimitEdit(interaction, rule) { const mentionLimitEmbed = embed.infos({ content: 'Please enter the new mention limit (1-50) or keep the current one.' }); await utils.editOrReply(interaction, { embeds: [mentionLimitEmbed], components: [] }); const filter = response => response.author.id === interaction.user.id; const collected = await interaction.channel.awaitMessages({ filter, max: 1, time: 60000, errors: ['time'] }).catch(() => null); if (collected && collected.first()) { const newMentionLimit = collected.first().content; if (newMentionLimit !== 'keep') { const number = parseInt(newMentionLimit, 10); if (isNaN(number) || number < 1 || number > 50) { await utils.editOrReply(interaction, { embeds: [embed.error({ content: 'Invalid number of mentions provided (must be between 1 and 50).' })] }); } else { await rule.edit({ triggerMetadata: { mentionTotalLimit: number } }); } } await utils.editOrReply(interaction, { embeds: [embed.success({ content: 'Mention limit successfully updated.' })] }); } else { await utils.editOrReply(interaction, { embeds: [embed.error({ content: 'No input received within the time limit.' })] }); } }