diff options
Diffstat (limited to 'warmachine/connections/slack.py')
| -rw-r--r-- | warmachine/connections/slack.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/warmachine/connections/slack.py b/warmachine/connections/slack.py index 0ef39dc..e4823df 100644 --- a/warmachine/connections/slack.py +++ b/warmachine/connections/slack.py | |||
| @@ -44,7 +44,7 @@ class SlackWS(Connection): | |||
| 44 | async def read(self): | 44 | async def read(self): |
| 45 | if self.ws: | 45 | if self.ws: |
| 46 | message = json.loads(await self.ws.recv()) | 46 | message = json.loads(await self.ws.recv()) |
| 47 | self.log.debug('REPLY: {}'.format(message)) | 47 | self.log.debug('new message parsed: {}'.format(message)) |
| 48 | # Slack is acknowledging a message was sent. Do nothing | 48 | # Slack is acknowledging a message was sent. Do nothing |
| 49 | if 'type' not in message and 'reply_to' in message: | 49 | if 'type' not in message and 'reply_to' in message: |
| 50 | # {'ok': True, | 50 | # {'ok': True, |
| @@ -82,12 +82,14 @@ class SlackWS(Connection): | |||
| 82 | if destination_id.startswith('U'): | 82 | if destination_id.startswith('U'): |
| 83 | destination_id = self.get_dm_id_by_user(destination_id) | 83 | destination_id = self.get_dm_id_by_user(destination_id) |
| 84 | 84 | ||
| 85 | await self._send(json.dumps({ | 85 | message = { |
| 86 | 'id': 1, # TODO: this should be a get_msgid call or something | 86 | 'id': 1, # TODO: this should be a get_msgid call or something |
| 87 | 'type': 'message', | 87 | 'type': 'message', |
| 88 | 'channel': destination_id, | 88 | 'channel': destination_id, |
| 89 | 'text': str(message) | 89 | 'text': str(message) |
| 90 | })) | 90 | } |
| 91 | self.log.debug("Saying {}".format(message)) | ||
| 92 | await self._send(json.dumps(message)) | ||
| 91 | 93 | ||
| 92 | async def _send(self, message): | 94 | async def _send(self, message): |
| 93 | """ | 95 | """ |
| @@ -202,9 +204,12 @@ class SlackWS(Connection): | |||
| 202 | # self.log.debug('updated_reconnect_url: {}'.format(self.reconnect_url)) | 204 | # self.log.debug('updated_reconnect_url: {}'.format(self.reconnect_url)) |
| 203 | 205 | ||
| 204 | def on_presence_change(self, msg): | 206 | def on_presence_change(self, msg): |
| 207 | """ | ||
| 208 | updates user's presence in ``self.user_map`` | ||
| 209 | """ | ||
| 205 | self.log.debug('updated_presence: {} ({}) was: {} is_now: {}'.format( | 210 | self.log.debug('updated_presence: {} ({}) was: {} is_now: {}'.format( |
| 206 | msg['user'], self.user_map[msg['user']]['name'], | 211 | msg['user'], self.user_map[msg['user']]['name'], |
| 207 | self.user_map[msg['user']]['presence'], | 212 | self.user_map[msg['user']].get('presence', '<undefined>'), |
| 208 | msg['presence'] | 213 | msg['presence'] |
| 209 | )) | 214 | )) |
| 210 | self.user_map[msg['user']]['presence'] = msg['presence'] | 215 | self.user_map[msg['user']]['presence'] = msg['presence'] |
| @@ -246,10 +251,12 @@ class SlackWS(Connection): | |||
| 246 | req = urllib.request.Request(url) | 251 | req = urllib.request.Request(url) |
| 247 | r = json.loads(urllib.request.urlopen(req).read().decode('utf-8')) | 252 | r = json.loads(urllib.request.urlopen(req).read().decode('utf-8')) |
| 248 | 253 | ||
| 254 | self.log.debug(r) | ||
| 249 | if channel.startswith('G'): | 255 | if channel.startswith('G'): |
| 250 | key = 'group' | 256 | key = 'group' |
| 251 | 257 | elif channel.startswith('C'): | |
| 252 | self.log.debug(pformat(r['group']['members'])) | 258 | key = 'channel' |
| 259 | self.log.debug(pformat(r[key]['members'])) | ||
| 253 | return r['group']['members'] | 260 | return r['group']['members'] |
| 254 | 261 | ||
| 255 | async def on_group_join(self, channel): | 262 | async def on_group_join(self, channel): |