From 1f9070c46f277830dff10576d4f9046a93bf39c1 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Mon, 15 Dec 2025 17:50:17 +0100 Subject: [PATCH] add optout and optin --- app.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 3c9fb77..454077d 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -import os, requests, random, http, re, dotenv +import os, requests, random, http, re, dotenv, json from constants import * @@ -6,6 +6,15 @@ from openrouter import OpenRouter from slack_bolt import App from slack_bolt.adapter.socket_mode import SocketModeHandler +if not os.path.exists("optouts.json"): + with open("optouts.json", "w") as file: + file.write("[]") + + optouts = [] +else: + with open("optouts.json", "r") as file: + optouts = json.load(file) + dotenv.load_dotenv(".env") openrouter_client = OpenRouter( @@ -74,6 +83,32 @@ def generate_quack_blocks(): } ] +@app.command("/optin") +def optin(ack, respond, command): + ack() + + optouts.remove(command["user_id"]) + + with open("optouts.json", "w") as file: + file.write(json.dumps(optouts, indent=4)) + + respond( + text="You have succesfully opted back in owo >:3", mrkdwn=False + ) + +@app.command("/optout") +def optout(ack, respond, command): + ack() + + optouts.append(command["user_id"]) + + with open("optouts.json", "w") as file: + file.write(json.dumps(optouts, indent=4)) + + respond( + text="You have succesfully opted out nyaaa >:c", mrkdwn=False + ) + @app.command("/catify") def catify(ack, say, command): text = command.get("text", "") @@ -221,6 +256,7 @@ def message_handler(event, say, client, message): message_text = event.get('text', '').lower() channel_id = message["channel"] message_ts = message["ts"] + user_id = message.get("user", "") if event.get("channel_type") == "im": messages = [{"role": "system", "content": AI_SYSTEM_PROMPT}] @@ -237,6 +273,9 @@ def message_handler(event, say, client, message): return + if user_id in optouts: + return + found_status_codes = [status_code for status_code in http_cat_codes if str(status_code) in message_text.lower().split()] if any([phrase in message_text.lower().split() for phrase in MEOW_PHRASES]):