diff --git a/.env.example b/.env.example index 006237e..87460f4 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,8 @@ 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 -ONLY_LOCAL_REPLIES="true" # reply to only users locally on your instance +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 OLLAMA_SYSTEM_PROMPT="" # system prompt - used to help tune the responses from the AI OLLAMA_MODEL="" # Ollama model for responses e.g dolphin-mistral:latest diff --git a/src/main.ts b/src/main.ts index a001d62..094eed8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,7 +13,10 @@ const prisma = new PrismaClient(); const envConfig = { pleromaInstanceUrl: process.env.PLEROMA_INSTANCE_URL || "", pleromaInstanceDomain: process.env.PLEROMA_INSTANCE_DOMAIN || "", - onlyLocalReplies: process.env.ONLY_LOCAL_REPLIES === "true" ? true : false, + whitelistOnly: process.env.ONLY_WHITELIST === "true" ? true : false || "true", + whitelistedDomains: process.env.WHITELISTED_DOMAINS + ? process.env.WHITELISTED_DOMAINS.split(",") + : [process.env.PLEROMA_INSTANCE_DOMAIN], ollamaUrl: process.env.OLLAMA_URL || "", ollamaSystemPrompt: process.env.OLLAMA_SYSTEM_PROMPT || @@ -123,16 +126,24 @@ const recordPendingResponse = async (notification: Notification) => { } }; +const isFromWhitelistedDomain = (fqn: string): boolean => { + try { + const domain = fqn.split("@")[1]; + if (envConfig.whitelistedDomains.includes(domain)) { + return true; + } + return false; + } catch (error: any) { + console.error(`Error with domain check: ${error.message}`); + return false; + } +}; + const generateOllamaRequest = async ( notification: Notification ): Promise => { - const { - onlyLocalReplies, - pleromaInstanceDomain, - ollamaModel, - ollamaSystemPrompt, - ollamaUrl, - } = envConfig; + const { whitelistOnly, ollamaModel, ollamaSystemPrompt, ollamaUrl } = + envConfig; try { if ( striptags(notification.status.content).includes("!prompt") && @@ -140,8 +151,8 @@ const generateOllamaRequest = async ( notification.type === "mention" ) { if ( - onlyLocalReplies && - !notification.status.account.fqn.includes(`@${pleromaInstanceDomain}`) + whitelistOnly && + !isFromWhitelistedDomain(notification.status.account.fqn) ) { return; }