aboutsummaryrefslogtreecommitdiffstats
path: root/warmachine/connections
diff options
context:
space:
mode:
Diffstat (limited to 'warmachine/connections')
-rw-r--r--warmachine/connections/slack.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/warmachine/connections/slack.py b/warmachine/connections/slack.py
index 79c80a2..07e026c 100644
--- a/warmachine/connections/slack.py
+++ b/warmachine/connections/slack.py
@@ -34,6 +34,8 @@ class SlackWS(Connection):
34 self.my_id = '000' 34 self.my_id = '000'
35 35
36 self.ws = None 36 self.ws = None
37 # used to give messages an id. slack requirement
38 self._internal_msgid = 0
37 39
38 self.status = INITALIZED 40 self.status = INITALIZED
39 41
@@ -53,7 +55,14 @@ class SlackWS(Connection):
53 55
54 async def read(self): 56 async def read(self):
55 if self.ws: 57 if self.ws:
56 message = json.loads(await self.ws.recv()) 58 try:
59 message = json.loads(await self.ws.recv())
60 except websockets.ConnectionClosed as e:
61 self.log.error('Connection Closed: {}'.format(e))
62 while not self.connect():
63 self.error('Trying to reconnect...')
64 await asyncio.sleep(300)
65 return
57 # Slack is acknowledging a message was sent. Do nothing 66 # Slack is acknowledging a message was sent. Do nothing
58 if 'reply_to' in message: 67 if 'reply_to' in message:
59 # {'ok': True, 68 # {'ok': True,
@@ -61,10 +70,10 @@ class SlackWS(Connection):
61 # 'text': "['!whois', 'synic']", 70 # 'text': "['!whois', 'synic']",
62 # 'ts': '1469743355.000150'} 71 # 'ts': '1469743355.000150'}
63 self.log.debug('Ignoring reply_to message: {}'.format( 72 self.log.debug('Ignoring reply_to message: {}'.format(
64 pformat(message))) 73 message))
65 return 74 return
66 75
67 self.log.debug('new slack message: {}'.format(pformat(message))) 76 self.log.debug('new slack message: {}'.format(message))
68 if message['type'] == 'message' and 'subtype' not in message: 77 if message['type'] == 'message' and 'subtype' not in message:
69 # Handle text messages from users 78 # Handle text messages from users
70 return await self.process_message(message) 79 return await self.process_message(message)
@@ -104,8 +113,9 @@ class SlackWS(Connection):
104 113
105 destination = self.get_dm_id_by_user(_user) 114 destination = self.get_dm_id_by_user(_user)
106 115
116 self._internal_msgid += 1
107 message = { 117 message = {
108 'id': 1, # TODO: this should be a get_msgid call or something 118 'id': self._internal_msgid,
109 'type': 'message', 119 'type': 'message',
110 'channel': destination, 120 'channel': destination,
111 'text': str(message) 121 'text': str(message)
@@ -301,7 +311,6 @@ class SlackWS(Connection):
301 for u_id in r[key]['members']: 311 for u_id in r[key]['members']:
302 users.append(self.user_map[u_id]['name']) 312 users.append(self.user_map[u_id]['name'])
303 313
304 self.log.debug(pformat(users))
305 return users 314 return users
306 315
307 async def on_group_join(self, channel): 316 async def on_group_join(self, channel):