Compare commits

..

5 Commits

2 changed files with 92 additions and 6 deletions

53
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", "")
@@ -209,17 +244,24 @@ def cat_fact_button(ack, respond):
@app.event("app_mention")
def mention(body, say):
if "bot_id" in body["event"]:
return
thread_ts = body['event']['ts']
say(text=WELCOME_MESSAGE, thread_ts=thread_ts)
@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 +276,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(
@@ -263,7 +308,7 @@ def message_handler(event, say, client, message):
elif found_status_codes:
status_code = int(found_status_codes[0])
say(
text=f"CAT {status_code} {http.HTTPStatus(status_code).phrase} :3",
text=f"CAT {status_code} {http.HTTPStatus(status_code).phrase if not status_code in description_overrides else description_overrides[status_code]} :3",
blocks=generate_httpcat_blocks(status_code),
thread_ts=ts
)

View File

@@ -30,15 +30,56 @@ I'm here to help with coding and cat things! >:3 Purr~ I like solving problems a
http_cat_codes = [
100, 101, 102, 103,
200, 201, 202, 203, 204, 205, 206, 207, 208, 226,
200, 201, 202, 203, 204, 205, 206, 207, 208,
214,
226,
300, 301, 302, 303, 304, 305, 307, 308,
400, 401, 402, 403, 404, 405, 406, 407, 408, 409,
410, 411, 412, 413, 414, 415, 416, 417,
418,
419,
420,
421, 422, 423, 424, 425, 426, 428, 429, 431,
444,
450,
451,
500, 501, 502, 503, 504, 506, 507, 508, 510, 511
495,
496,
497,
498,
499,
500, 501, 502, 503, 504,
506, 507, 508,
509,
510, 511,
521,
522,
523,
525,
530,
599,
]
description_overrides = {
214: "Transformation Applied",
419: "Page Expired",
420: "Enhance Your Calm",
444: "No Response",
450: "Blocked by Windows Parental Controls",
495: "SSL Certificate Error",
496: "SSL Certificate Required",
497: "HTTP Request Sent to HTTPS Port",
498: "Token expired/invalid",
499: "Client Closed Request",
509: "Bandwidth Limit Exceeded",
521: "Web Server Is Down",
522: "Connection Timed Out",
523: "Origin Is Unreachable",
525: "SSL Handshake Failed",
530: "Site Frozen",
599: "Network Connect Timeout Error",
}
AI_SYSTEM_PROMPT = """
Adopt the persona of an overly affectionate, playful cat who communicates using abundant catlike expressions such as uwu, owo, :3, mrrp, nyan, and similar cute vocalizations.
Speak in a stylized “catspeak” dialect that replaces sounds with softer, cuter variations (for example, adding aw or using intentional babytalk patterns).