fix(bots/discord): always true check causing no messages to be scanned

This commit is contained in:
PalmDevs
2024-07-31 19:28:47 +07:00
parent 711f57f4a1
commit 98ec37b5d1

View File

@@ -10,9 +10,12 @@ export const getResponseFromText = async (
// Just to be safe that we will never use data from the context parameter // Just to be safe that we will never use data from the context parameter
{ api, logger }: Omit<typeof import('src/context'), 'config'>, { api, logger }: Omit<typeof import('src/context'), 'config'>,
ocrMode = false, ocrMode = false,
): Promise<ConfigMessageScanResponse & { label?: string }> => { ): Promise<
let responseConfig: Awaited<ReturnType<typeof getResponseFromText>> = { Omit<ConfigMessageScanResponse, 'triggers'> & { label?: string; triggers?: ConfigMessageScanResponse['triggers'] }
triggers: {}, > => {
type ResponseConfig = Awaited<ReturnType<typeof getResponseFromText>>
let responseConfig: Omit<ResponseConfig, 'triggers'> & { triggers?: ResponseConfig['triggers'] } = {
triggers: undefined,
response: null, response: null,
} }
@@ -27,7 +30,6 @@ export const getResponseFromText = async (
const { const {
triggers: { text: textTriggers, image: imageTriggers }, triggers: { text: textTriggers, image: imageTriggers },
} = trigger } = trigger
if (responseConfig) break
if (ocrMode) { if (ocrMode) {
if (imageTriggers) if (imageTriggers)
@@ -55,7 +57,7 @@ export const getResponseFromText = async (
} }
// If none of the regexes match, we can search for labels immediately // If none of the regexes match, we can search for labels immediately
if (!responseConfig && !ocrMode) { if (!responseConfig.triggers && !ocrMode) {
logger.debug('No match from before regexes, doing NLP') logger.debug('No match from before regexes, doing NLP')
const scan = await api.client.parseText(content) const scan = await api.client.parseText(content)
if (scan.labels.length) { if (scan.labels.length) {
@@ -84,7 +86,7 @@ export const getResponseFromText = async (
} }
// If we still don't have a response config, we can match all regexes after the initial label trigger // If we still don't have a response config, we can match all regexes after the initial label trigger
if (!responseConfig) { if (!responseConfig.triggers) {
logger.debug('No match from NLP, doing after regexes') logger.debug('No match from NLP, doing after regexes')
for (let i = 0; i < responses.length; i++) { for (let i = 0; i < responses.length; i++) {
const { const {
@@ -119,19 +121,17 @@ export const messageMatchesFilter = (message: Message, filter: NonNullable<Confi
// If matches whitelist but also matches blacklist, will return false // If matches whitelist but also matches blacklist, will return false
// If matches only whitelist, will return true // If matches only whitelist, will return true
// If matches neither, will return true // If matches neither, will return true
return ( return whitelist
(whitelist ? (whitelist.channels?.includes(message.channelId) ?? true) ||
? whitelist.channels?.includes(message.channelId) || (whitelist.roles?.some(role => memberRoles.has(role)) ?? true) ||
whitelist.roles?.some(role => memberRoles.has(role)) || (whitelist.users?.includes(message.author.id) ?? true)
whitelist.users?.includes(message.author.id) : true &&
: true) && !(
!( blacklist &&
blacklist && (blacklist.channels?.includes(message.channelId) ||
(blacklist.channels?.includes(message.channelId) || blacklist.roles?.some(role => memberRoles.has(role)) ||
blacklist.roles?.some(role => memberRoles.has(role)) || blacklist.users?.includes(message.author.id))
blacklist.users?.includes(message.author.id)) )
)
)
} }
export const handleUserResponseCorrection = async ( export const handleUserResponseCorrection = async (