mirror of
https://github.com/csd4ni3l/meow-bot.git
synced 2026-01-01 04:23:49 +01:00
add optout and optin
This commit is contained in:
41
app.py
41
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]):
|
||||
|
||||
Reference in New Issue
Block a user