little more error checking/correction/QOL
This commit is contained in:
13
src/main.ts
13
src/main.ts
@ -126,15 +126,19 @@ const recordPendingResponse = async (notification: Notification) => {
|
||||
}
|
||||
};
|
||||
|
||||
const isFromWhitelistedDomain = (fqn: string): boolean => {
|
||||
const isFromWhitelistedDomain = async (
|
||||
notification: Notification
|
||||
): Promise<boolean> => {
|
||||
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)) {
|
||||
|
Reference in New Issue
Block a user