From a04cb9a6ad6cac31776a440c54fac873ab65d9ee Mon Sep 17 00:00:00 2001 From: matty Date: Sun, 3 Aug 2025 19:43:05 +0000 Subject: [PATCH] some abstraction and I'm gonna kill myself --- src/main.ts | 24 ++++-------------------- src/util.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main.ts b/src/main.ts index 80aa6eb..aa3ae0b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,7 @@ import { recordPendingResponse, trimInputData, selectRandomEmoji, + shouldContinue, } from "./util.js"; export const prisma = new PrismaClient(); @@ -59,25 +60,10 @@ const ollamaConfig: OllamaConfigOptions = { const generateOllamaRequest = async ( notification: Notification ): Promise => { - const { - whitelistOnly, - ollamaModel, - ollamaSystemPrompt, - ollamaUrl, - botAccountId, - } = envConfig; + const { whitelistOnly, ollamaModel, ollamaSystemPrompt, ollamaUrl } = + envConfig; try { - console.log(trimInputData(notification.status.content)); - if ( - // striptags(notification.status.content).includes("!prompt") && - !notification.status.account.bot && // sanity check, sort of - notification.type === "mention" && - (notification.status.in_reply_to_account_id === botAccountId || - notification.status.in_reply_to_account_id === null) && - trimInputData(notification.status.content).split(" ").includes("Lexi") - // only reply to mentions when the bot is the direct recipient or when an @ is at the top level of a conversation chain, or when the AI is @ directly - // notification.status.visibility !== "private" // for safety, let's only respond to public messages - ) { + if (shouldContinue(notification)) { if (whitelistOnly && !isFromWhitelistedDomain(notification)) { await deleteNotification(notification); return; @@ -87,10 +73,8 @@ const generateOllamaRequest = async ( } await recordPendingResponse(notification); await storeUserData(notification); - // console.log(trimInputData(notification.status.content)); const ollamaRequestBody: OllamaRequest = { model: ollamaModel, - // prompt: trimInputData(notification.status.content), prompt: `${notification.status.account.fqn} says: ${trimInputData( notification.status.content )}`, diff --git a/src/util.ts b/src/util.ts index d0fbd81..90078cb 100644 --- a/src/util.ts +++ b/src/util.ts @@ -34,6 +34,34 @@ const recordPendingResponse = async (notification: Notification) => { } }; +const shouldContinue = (notification: Notification) => { + // wow this is bad + try { + const { botAccountId } = envConfig; + const statusContent = trimInputData(notification.status.content); + if ( + notification.status.visibility !== "private" && + !notification.account.bot && + notification.type === "mention" + ) { + if (notification.status.in_reply_to_account_id === botAccountId) { + return true; + } else if ( + notification.status.in_reply_to_account_id !== botAccountId && + statusContent.includes("Lexi") + ) { + return true; + } else { + return false; + } + } + } catch (error: unknown) { + if (error instanceof Error) { + throw new Error(error.message); + } + } +}; + const isFromWhitelistedDomain = (notification: Notification): boolean => { try { const domain = notification.status.account.fqn.split("@")[1]; @@ -76,4 +104,5 @@ export { trimInputData, recordPendingResponse, isFromWhitelistedDomain, + shouldContinue, };