This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack_bot.py
63 lines (58 loc) · 2.7 KB
/
slack_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
import re
import json
import datetime
import time
import random
from slackclient import SlackClient
def options(day):
restaurants = ['japochungo','covas','japo4','pimpa','girasuelos','suamu','cuoco','trobada','nurivan','milcasas','quaranta','fantastic','motobar','sushifresh','brasas']
if day == 4:
return 'chipo'
elif day == 0 or day == 3:
return restaurants[1:]
else:
return restaurants
token = "xxx-here-your-token-xxx"
sc = SlackClient(token)
today = datetime.datetime.today().weekday()
options_today = options(today)
if sc.rtm_connect():
while True:
x = sc.rtm_read()
if len(x) > 0 and 'text' in x[0].keys():
if 'user' not in x[0].keys(): continue
if x[0]['channel'] != 'C0PLSUV5K': continue
name = sc.api_call("users.info",user=x[0]['user'])
rname = json.loads(name)
#print x[0]
print rname['user']['name'],[rname['user']['id']],'channel',[x[0]['channel']],x[0]['text']
if x[0]['text'] == 'help':
sc.rtm_send_message(x[0]['channel'], "activate me using '!eat start' without commas")
if re.match(r'!eat',x[0]['text']) != None:
paction = str(x[0]['text'])
action = paction.lstrip('!eat ')
if action == 'start':
sc.rtm_send_message(x[0]['channel'], "Starting WheretoEatProEdition")
restaurants_chosen = []
msg = "Today's options are: %s" % options_today
sc.rtm_send_message(x[0]['channel'],msg)
sc.rtm_send_message(x[0]['channel'],"Type !eat <option> to add restaurant to today's pool")
sc.rtm_send_message(x[0]['channel'], "Type !eat check to check chosen restaurants so far")
elif action in options_today:
restaurants_chosen.append(action)
msg = "Restaurant '%s' added" % action
sc.rtm_send_message(x[0]['channel'], msg)
elif action == 'check':
msg = "Restaurants in today's pool are:%s" % restaurants_chosen
sc.rtm_send_message(x[0]['channel'], msg)
elif action == 'finish':
msg = "From this list %s the winner is...." % restaurants_chosen
sc.rtm_send_message(x[0]['channel'], msg)
winner = random.choice(restaurants_chosen)
sc.rtm_send_message(x[0]['channel'], winner)
restaurants_chosen = []
else:
sc.rtm_send_message(x[0]['channel'], "Incorrect Command")
time.sleep(1)
else:
print "Connection Failed, invalid token?"