-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
70 lines (53 loc) · 1.41 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import requests
import random
from flask import Flask, request
app = Flask(__name__)
@app.route("/", methods=["GET"])
def home():
return "RA Bot is running :)"
@app.route("/", methods=["POST"])
def receive():
print("Incoming message:")
data = request.get_json()
print(data)
# prevent self-reply
if data["sender_type"] != "RA BOT":
read(data["text"].lower())
if data["text"].startswith("/ping"):
send(data["name"] + " pinged me!")
return "ok", 200
def chicken_tenders(food):
if "Chicken Tenders" in food:
return True
return False
def read(msg):
text = msg.split(" ")
if msg == "/menu":
send(
"""RA BOT MENU: \n
Type in a command! \n
Pick a num between 1-10: /pick \n
Flip a coin: /flip \n
Phone Numbers: /numbers \n"""
)
elif msg == "/pick":
send(str(random.randint(1, 10)))
elif msg == "/flip":
toss = random.randint(1, 2)
if toss == 1:
send("tails")
else:
send("heads")
elif msg == "/numbers":
send(
"""Jason: 240-340-3777\n
UMPD: 301-405-3555\n
4-Work: 301-314-9675"""
)
def send(msg):
data = {
"bot_id": os.getenv("BOT_ID"),
"text": msg,
}
r = requests.post("https://api.groupme.com/v3/bots/post", json=data)