mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(bots/discord): reset counter when reconnected to api, redo message scan filter logic
This commit is contained in:
@@ -43,4 +43,4 @@
|
||||
"discord-api-types": "^0.37.92",
|
||||
"drizzle-kit": "^0.22.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
@@ -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))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user