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 { |   try { | ||||||
|     const domain = fqn.split("@")[1]; |     const domain = notification.status.account.fqn.split("@")[1]; | ||||||
|     if (envConfig.whitelistedDomains.includes(domain)) { |     if (envConfig.whitelistedDomains.includes(domain)) { | ||||||
|       return true; |       return true; | ||||||
|     } |     } | ||||||
|     console.log( |     console.log( | ||||||
|       `Rejecting prompt request from non-whitelisted domain: ${domain}` |       `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; |     return false; | ||||||
|   } catch (error: any) { |   } catch (error: any) { | ||||||
|     console.error(`Error with domain check: ${error.message}`); |     console.error(`Error with domain check: ${error.message}`); | ||||||
| @ -153,10 +157,7 @@ const generateOllamaRequest = async ( | |||||||
|       !notification.status.account.bot && // sanity check, sort of |       !notification.status.account.bot && // sanity check, sort of | ||||||
|       notification.type === "mention" |       notification.type === "mention" | ||||||
|     ) { |     ) { | ||||||
|       if ( |       if (whitelistOnly && !(await isFromWhitelistedDomain(notification))) { | ||||||
|         whitelistOnly && |  | ||||||
|         !isFromWhitelistedDomain(notification.status.account.fqn) |  | ||||||
|       ) { |  | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|       if (await alreadyRespondedTo(notification)) { |       if (await alreadyRespondedTo(notification)) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user