add optout and optin

This commit is contained in:
csd4ni3l
2025-12-15 17:50:17 +01:00
parent 58de106609
commit 1f9070c46f

41
app.py
View File

@@ -1,4 +1,4 @@
import os, requests, random, http, re, dotenv import os, requests, random, http, re, dotenv, json
from constants import * from constants import *
@@ -6,6 +6,15 @@ from openrouter import OpenRouter
from slack_bolt import App from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler 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") dotenv.load_dotenv(".env")
openrouter_client = OpenRouter( 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") @app.command("/catify")
def catify(ack, say, command): def catify(ack, say, command):
text = command.get("text", "") text = command.get("text", "")
@@ -221,6 +256,7 @@ def message_handler(event, say, client, message):
message_text = event.get('text', '').lower() message_text = event.get('text', '').lower()
channel_id = message["channel"] channel_id = message["channel"]
message_ts = message["ts"] message_ts = message["ts"]
user_id = message.get("user", "")
if event.get("channel_type") == "im": if event.get("channel_type") == "im":
messages = [{"role": "system", "content": AI_SYSTEM_PROMPT}] messages = [{"role": "system", "content": AI_SYSTEM_PROMPT}]
@@ -237,6 +273,9 @@ def message_handler(event, say, client, message):
return 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()] 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]): if any([phrase in message_text.lower().split() for phrase in MEOW_PHRASES]):