Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from aerickson/output_can_take_username
Browse files Browse the repository at this point in the history
output can take a username as an arg
  • Loading branch information
Roach committed Feb 5, 2018
2 parents 6a13371 + ad1586b commit a45af00
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions rtmbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import time
import logging
import json

from slackclient import SlackClient

Expand Down Expand Up @@ -116,12 +117,26 @@ def output(self):
for plugin in self.bot_plugins:
limiter = False
for output in plugin.do_output():
channel = self.slack_client.server.channels.find(output[0])
if channel is not None and output[1] is not None:
destination = output[0]
message = output[1]
# things that start with U are users. convert to an IM channel.
if destination.startswith('U'):
try:
result = json.loads(self.slack_client.api_call('im.open', user=destination))
except ValueError:
self._dbg("Parse error on im.open call results!")
channel = self.slack_client.server.channels.find(
result.get(u'channel', {}).get(u'id', None))
elif destination.startswith('G'):
result = self.slack_client.api_call('groups.open', channel=destination)
channel = self.slack_client.server.channels.find(destination)
else:
channel = self.slack_client.server.channels.find(destination)
if channel is not None and message is not None:
if limiter:
time.sleep(.1)
limiter = False
channel.send_message(output[1])
channel.send_message(message)
limiter = True

def crons(self):
Expand Down

0 comments on commit a45af00

Please sign in to comment.