File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 44import os
55import time
66import logging
7+ import json
78
89from slackclient import SlackClient
910
@@ -116,12 +117,26 @@ def output(self):
116117 for plugin in self .bot_plugins :
117118 limiter = False
118119 for output in plugin .do_output ():
119- channel = self .slack_client .server .channels .find (output [0 ])
120- if channel is not None and output [1 ] is not None :
120+ destination = output [0 ]
121+ message = output [1 ]
122+ # things that start with U are users. convert to an IM channel.
123+ if destination .startswith ('U' ):
124+ try :
125+ result = json .loads (self .slack_client .api_call ('im.open' , user = destination ))
126+ except ValueError :
127+ self ._dbg ("Parse error on im.open call results!" )
128+ channel = self .slack_client .server .channels .find (
129+ result .get (u'channel' , {}).get (u'id' , None ))
130+ elif destination .startswith ('G' ):
131+ result = self .slack_client .api_call ('groups.open' , channel = destination )
132+ channel = self .slack_client .server .channels .find (destination )
133+ else :
134+ channel = self .slack_client .server .channels .find (destination )
135+ if channel is not None and message is not None :
121136 if limiter :
122137 time .sleep (.1 )
123138 limiter = False
124- channel .send_message (output [ 1 ] )
139+ channel .send_message (message )
125140 limiter = True
126141
127142 def crons (self ):
You can’t perform that action at this time.
0 commit comments