fix(bots/discord): reset counter when reconnected to api, redo message scan filter logic

This commit is contained in:
PalmDevs
2024-07-31 00:21:38 +07:00
parent 3188f8dbed
commit d234d79310
3 changed files with 23 additions and 10 deletions

View File

@@ -43,4 +43,4 @@
"discord-api-types": "^0.37.92",
"drizzle-kit": "^0.22.8"
}
}
}

View File

@@ -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')
})

View File

@@ -113,15 +113,24 @@ export const messageMatchesFilter = (message: Message, filter: NonNullable<Confi
if (!filter) return true
const memberRoles = new Set(message.member?.roles.cache.keys())
const blFilter = filter.blacklist
const { blacklist, whitelist } = filter
// If matches blacklist, will return false
// Any other case, will return true
return !(
blFilter &&
(blFilter.channels?.includes(message.channelId) ||
blFilter.roles?.some(role => 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))
)
)
}