some abstraction and I'm gonna kill myself

This commit is contained in:
2025-08-03 19:43:05 +00:00
parent 2111a47411
commit a04cb9a6ad
2 changed files with 33 additions and 20 deletions

View File

@ -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<OllamaResponse | undefined> => {
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
)}`,

View File

@ -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,
};