Compare commits

...

4 Commits

48
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 *
@@ -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("/meowbot-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"
)
@app.command("/meowbot-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"
)
@app.command("/catify")
def catify(ack, say, command):
text = command.get("text", "")
@@ -214,12 +249,16 @@ def mention(body, say):
@app.event("message")
def message_handler(event, say, client, message):
if "bot_id" in event:
return
ts = event.get('ts')
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" and "bot_id" not in event:
if event.get("channel_type") == "im":
messages = [{"role": "system", "content": AI_SYSTEM_PROMPT}]
messages.extend([{"role": "assistant" if "bot_id" in msg else "user", "content": msg.get("text", "")} for msg in client.conversations_history(channel=channel_id, limit=AI_CONTEXT_MSG_LIMIT).get("messages", [])])
messages.append({"role": "user", "content": message_text})
@@ -234,7 +273,10 @@ def message_handler(event, say, client, message):
return
found_status_codes = [status_code for status_code in http_cat_codes if str(status_code) in message_text.lower()]
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]):
say(