From 227a8006629268b1f90fd9a1a1c3e49fdb1c8535 Mon Sep 17 00:00:00 2001 From: Wizzard Date: Mon, 19 Feb 2024 14:46:56 -0500 Subject: [PATCH] Expand filter --- main.js | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index 0ced04f..96ca759 100644 --- a/main.js +++ b/main.js @@ -68,14 +68,37 @@ client.on('messageCreate', async message => { if (message.channel.id === COMMAND_CHANNEL_ID && message.content.startsWith('.filter')) { const args = message.content.split(' '); if (args.length < 3) { - return message.reply("Usage: .filter ").then(msg => setTimeout(() => msg.delete(), 5000)); + return message.reply("Usage: .filter add|remove|clear ").then(msg => setTimeout(() => msg.delete(), 5000)); } - const [_, channelId, userId] = args; - channelSettings.filters[channelId] = userId; - fs.writeFileSync(settingsFilePath, JSON.stringify(channelSettings, null, 2)); + const channelId = args[1]; + const action = args[2]; + const userId = args[3]; - return message.reply(`Messages from user ID ${userId} in channel ID ${channelId} will now be specifically logged.`).then(msg => setTimeout(() => msg.delete(), 5000)); + channelSettings.filters[channelId] = channelSettings.filters[channelId] || []; + + switch (action) { + case 'add': + if (!channelSettings.filters[channelId].includes(userId)) { + channelSettings.filters[channelId].push(userId); + message.reply(`Added user ID ${userId} to the filter for channel ID ${channelId}.`).then(msg => setTimeout(() => msg.delete(), 5000)); + } else { + message.reply(`User ID ${userId} is already in the filter for channel ID ${channelId}.`).then(msg => setTimeout(() => msg.delete(), 5000)); + } + break; + case 'remove': + channelSettings.filters[channelId] = channelSettings.filters[channelId].filter(id => id !== userId); + message.reply(`Removed user ID ${userId} from the filter for channel ID ${channelId}.`).then(msg => setTimeout(() => msg.delete(), 5000)); + break; + case 'clear': + channelSettings.filters[channelId] = []; + message.reply(`Cleared all filters for channel ID ${channelId}.`).then(msg => setTimeout(() => msg.delete(), 5000)); + break; + default: + message.reply("Invalid action. Use 'add', 'remove', or 'clear'.").then(msg => setTimeout(() => msg.delete(), 5000)); + } + + fs.writeFileSync(settingsFilePath, JSON.stringify(channelSettings, null, 2)); } @@ -106,15 +129,15 @@ client.on('messageCreate', async message => { if (channelMappings[message.channel.id]) { if (message.author.id === client.user.id) return; - const filterUserId = channelSettings.filters[message.channel.id]; - let shouldLog = true; + const filterUserIds = channelSettings.filters[message.channel.id] || []; + let shouldLog = filterUserIds.length === 0; - if (filterUserId) { - const isFromFilteredUser = message.author.id === filterUserId; - const isReplyToFilteredUser = message.reference && message.reference.messageId ? await checkIfReplyToFilteredUser(message, filterUserId) : false; - const isMentioningFilteredUser = message.mentions.users.has(filterUserId); + if (filterUserIds.length > 0) { + const isFromFilteredUsers = filterUserIds.includes(message.author.id); + const isReplyToFilteredUsers = message.reference && message.reference.messageId ? await checkIfReplyToFilteredUsers(message, filterUserIds) : false; + const isMentioningFilteredUsers = message.mentions.users.some(user => filterUserIds.includes(user.id)); - shouldLog = isFromFilteredUser || isReplyToFilteredUser || isMentioningFilteredUser; + shouldLog = isFromFilteredUsers || isReplyToFilteredUsers || isMentioningFilteredUsers; } if (!shouldLog) return;