From aaf4adcf0618e35002601cbcc772c461a3fe66c8 Mon Sep 17 00:00:00 2001 From: matty Date: Sun, 3 Aug 2025 18:56:05 +0000 Subject: [PATCH] don't reply when not addressed --- .env.example | 1 + src/main.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 835f81d..336112b 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ DATABASE_URL="file:../dev.db" # SQLite database relative to the ./prisma path PLEROMA_INSTANCE_URL="https://instance.tld" # Pleroma instance full URL including scheme PLEROMA_INSTANCE_DOMAIN="instance.tld" # used if you want to only want to respond to people from a particular instance +PLEROMA_ACCOUNT_ID="" # obtained from /api/v1/accounts/{nickname} - used so we don't spam mentions when not directly addressed ONLY_WHITELIST="true" # change to "false" if you want to accept prompts from any and all domains - *** USE WITH CAUTION *** WHITELISTED_DOMAINS="" # comma separated list of domains you want to allow the bot to accept prompts from (i.e. poa.st,nicecrew.digital,detroitriotcity.com,decayable.ink) OLLAMA_URL="http://localhost:11434" # OLLAMA connection URL diff --git a/src/main.ts b/src/main.ts index 4308dd5..80aa6eb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -42,6 +42,7 @@ export const envConfig = { adHocPostInterval: process.env.RANDOM_POST_INTERVAL ? parseInt(process.env.RANDOM_POST_INTERVAL) : 3600000, + botAccountId: process.env.PLEROMA_ACCOUNT_ID, }; const ollamaConfig: OllamaConfigOptions = { @@ -58,13 +59,23 @@ const ollamaConfig: OllamaConfigOptions = { const generateOllamaRequest = async ( notification: Notification ): Promise => { - const { whitelistOnly, ollamaModel, ollamaSystemPrompt, ollamaUrl } = - envConfig; + const { + whitelistOnly, + ollamaModel, + ollamaSystemPrompt, + ollamaUrl, + botAccountId, + } = 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.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 (whitelistOnly && !isFromWhitelistedDomain(notification)) {