-
Notifications
You must be signed in to change notification settings - Fork 0
/
prick.py
41 lines (31 loc) · 914 Bytes
/
prick.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
import configparser
import re
from slackclient import SlackClient
import requests
import handlers
def cmd_parser(text):
# FIXME: so tired
parsed = re.match(r'^(live-who)\s+(.+)?$', text)
if not parsed:
return None, None
parsed = parsed.groups()
return parsed[0], parsed[1:]
echo = lambda x: x
config = configparser.ConfigParser()
config.read('.env')
token = config['slack']['API_TOKEN']
client = SlackClient(token)
if client.rtm_connect():
while client.server.connected is True:
msg = client.rtm_read()
if not msg or msg[0].get('type', '') != 'message':
continue
(cmd, args) = cmd_parser(msg[0]['text'])
if not cmd:
continue
handler = handlers.of.get(cmd)
if not handler:
continue
client.rtm_send_message(msg[0]['channel'], handler(*args))
else:
print('Connection failed')