From d234d79310caed9c43e14a905f9ef46a110e071d Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Wed, 31 Jul 2024 00:21:38 +0700 Subject: [PATCH] fix(bots/discord): reset counter when reconnected to api, redo message scan filter logic --- bots/discord/package.json | 2 +- bots/discord/src/events/api/ready.ts | 6 ++++- bots/discord/src/utils/discord/messageScan.ts | 25 +++++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/bots/discord/package.json b/bots/discord/package.json index b6f1947..eaedcf5 100644 --- a/bots/discord/package.json +++ b/bots/discord/package.json @@ -43,4 +43,4 @@ "discord-api-types": "^0.37.92", "drizzle-kit": "^0.22.8" } -} \ No newline at end of file +} diff --git a/bots/discord/src/events/api/ready.ts b/bots/discord/src/events/api/ready.ts index 94e55df..99fafac 100644 --- a/bots/discord/src/events/api/ready.ts +++ b/bots/discord/src/events/api/ready.ts @@ -1,3 +1,7 @@ import { on, withContext } from '$utils/api/events' -withContext(on, 'ready', ({ logger }) => void logger.info('Connected to the bot API')) +withContext(on, 'ready', ({ api, logger }) => { + // Reset disconnect count, so it doesn't meet the threshold for an accidental disconnect + api.disconnectCount = 0 + logger.info('Connected to the bot API') +}) diff --git a/bots/discord/src/utils/discord/messageScan.ts b/bots/discord/src/utils/discord/messageScan.ts index 8c285bd..e9ca7d9 100644 --- a/bots/discord/src/utils/discord/messageScan.ts +++ b/bots/discord/src/utils/discord/messageScan.ts @@ -113,15 +113,24 @@ export const messageMatchesFilter = (message: Message, filter: NonNullable memberRoles.has(role)) || - blFilter.users?.includes(message.author.id)) + // If matches only blacklist, will return false + // If matches whitelist but also matches blacklist, will return false + // If matches only whitelist, will return true + // If matches neither, will return true + return ( + (whitelist + ? whitelist.channels?.includes(message.channelId) || + whitelist.roles?.some(role => memberRoles.has(role)) || + whitelist.users?.includes(message.author.id) + : true) && + !( + blacklist && + (blacklist.channels?.includes(message.channelId) || + blacklist.roles?.some(role => memberRoles.has(role)) || + blacklist.users?.includes(message.author.id)) + ) ) }