Add meow button, cat facts

This commit is contained in:
csd4ni3l
2025-12-11 16:39:52 +01:00
parent a1a2020ea5
commit 471d5cf901

74
app.py
View File

@@ -1,4 +1,4 @@
import os, requests import os, requests, random
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
@@ -20,6 +20,31 @@ QUACK_PHRASES = ["quack", "duck", "gizzy"]
app = App(token=os.environ.get("SLACK_BOT_TOKEN")) app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
@app.command("/meow_button")
def meow_button(ack, say):
ack()
say(
text="Meow! :3",
blocks=[
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {"type": "plain_text", "text": "Click me :3"},
"action_id": "meow_button",
"value": "meow"
}
]
}
]
)
@app.action("meow_button")
def meow_action(ack, say):
ack()
say(text=random.choice(MEOW_PHRASES))
@app.command("/meow") @app.command("/meow")
def meow(ack, say): def meow(ack, say):
ack() ack()
@@ -58,6 +83,53 @@ def quack(ack, say):
] ]
) )
@app.command("/cat_fact")
def cat_fact(ack, say):
ack()
fact = requests.get("https://catfact.ninja/fact").json()["fact"]
say(
text="Cat Fact: " + fact,
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Cat Fact: " + fact
},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "New fact"},
"action_id": "cat_fact_button",
"value": "meow"
}
}
]
)
@app.action("cat_fact_button")
def cat_fact_button(ack, respond):
ack()
fact = requests.get("https://catfact.ninja/fact").json()["fact"]
respond(
replace_original=True,
text="Cat Fact: " + fact,
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Cat Fact: " + fact
},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "New fact"},
"action_id": "cat_fact_button",
"value": "meow"
}
}
]
)
@app.event("message") @app.event("message")
def message_handler(body, say): def message_handler(body, say):
message_text = body.get('event', {}).get('text', '').lower() message_text = body.get('event', {}).get('text', '').lower()