-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.py
24 lines (19 loc) · 967 Bytes
/
event.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
import test
class Event:
def __init__(self, bot):
self.bot = bot
self.command = test.Command()
def wait_for_event(self):
events = self.bot.slack_client.rtm_read()
if events and len(events) > 0:
for event in events:
#print event
self.parse_event(event)
def parse_event(self, event):
if event and 'text' in event and self.bot.bot_id in event['text']:
self.handle_event(event['user'], event['text'].split(self.bot.bot_id)[1].strip().lower(), event['channel'])
def handle_event(self, user, command, channel):
if command and channel:
print("Received command: " + command + " in channel: " + channel + " from user: " + user)
response = self.command.handle_command(user, command)
self.bot.slack_client.api_call("chat.postMessage", channel=channel, text=response, as_user=True)