diff --git a/src/main.ts b/src/main.ts index 546ab6a..eceffe3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -126,15 +126,19 @@ const recordPendingResponse = async (notification: Notification) => { } }; -const isFromWhitelistedDomain = (fqn: string): boolean => { +const isFromWhitelistedDomain = async ( + notification: Notification +): Promise => { try { - const domain = fqn.split("@")[1]; + const domain = notification.status.account.fqn.split("@")[1]; if (envConfig.whitelistedDomains.includes(domain)) { return true; } console.log( `Rejecting prompt request from non-whitelisted domain: ${domain}` ); + // delete the notification so we don't keep trying to fetch it + await deleteNotification(notification); return false; } catch (error: any) { console.error(`Error with domain check: ${error.message}`); @@ -153,10 +157,7 @@ const generateOllamaRequest = async ( !notification.status.account.bot && // sanity check, sort of notification.type === "mention" ) { - if ( - whitelistOnly && - !isFromWhitelistedDomain(notification.status.account.fqn) - ) { + if (whitelistOnly && !(await isFromWhitelistedDomain(notification))) { return; } if (await alreadyRespondedTo(notification)) {