17
17
18
18
import slack_reformat
19
19
20
- import secrets
20
+ import local_secrets
21
21
22
- REDIS_USERS = secrets . REDIS_PREFIX + ':users:'
23
- REDIS_BOTS = secrets . REDIS_PREFIX + ':bots:'
24
- REDIS_CHANNELS = secrets . REDIS_PREFIX + ':channels:'
25
- REDIS_CHANNELS_BY_NAME = secrets . REDIS_PREFIX + ':channels.by.name:'
22
+ REDIS_USERS = REDIS_PREFIX + ':users:'
23
+ REDIS_BOTS = REDIS_PREFIX + ':bots:'
24
+ REDIS_CHANNELS = REDIS_PREFIX + ':channels:'
25
+ REDIS_CHANNELS_BY_NAME = REDIS_PREFIX + ':channels.by.name:'
26
26
REDIS_MSG_SLACK_TO_ZULIP = {
27
- secrets . PUBLIC_TWO_WAY_STREAM : secrets . REDIS_PREFIX + ':msg.slack.to.zulip.pub:' ,
28
- secrets . ZULIP_LOG_PUBLIC_STREAM : secrets . REDIS_PREFIX + ':msg.slack.to.zulip:' ,
29
- secrets . ZULIP_LOG_PRIVATE_STREAM : secrets . REDIS_PREFIX + ':msg.slack.to.zulip.priv:'
27
+ PUBLIC_TWO_WAY_STREAM : REDIS_PREFIX + ':msg.slack.to.zulip.pub:' ,
28
+ ZULIP_LOG_PUBLIC_STREAM : REDIS_PREFIX + ':msg.slack.to.zulip:' ,
29
+ ZULIP_LOG_PRIVATE_STREAM : REDIS_PREFIX + ':msg.slack.to.zulip.priv:'
30
30
}
31
31
32
32
GROUP_UPDATES = ['channel_archive' , 'channel_join' , 'channel_leave' ,
41
41
42
42
_LOGGER = logging .getLogger (__name__ )
43
43
44
- if secrets . GROUPME_ENABLE :
44
+ if GROUPME_ENABLE :
45
45
context = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
46
- context .load_cert_chain (secrets . SSL_CERT_CHAIN_PATH , secrets . SSL_CERT_KEY_PATH )
46
+ context .load_cert_chain (SSL_CERT_CHAIN_PATH , SSL_CERT_KEY_PATH )
47
47
48
48
class SlackHandler (logging .StreamHandler ):
49
49
def __init__ (self , web_client , event_loop , channel_id ):
@@ -92,16 +92,16 @@ def __init__(self):
92
92
93
93
_LOGGER .debug ('connecting to redis' )
94
94
self .redis = redis .Redis (
95
- host = secrets . REDIS_HOSTNAME ,
96
- port = secrets . REDIS_PORT ,
97
- password = secrets . REDIS_PASSWORD ,
95
+ host = REDIS_HOSTNAME ,
96
+ port = REDIS_PORT ,
97
+ password = REDIS_PASSWORD ,
98
98
charset = "utf-8" ,
99
99
decode_responses = True )
100
100
101
101
_LOGGER .debug ('connecting to zulip' )
102
- self .zulip_client = zulip .Client (email = secrets . ZULIP_BOT_EMAIL ,
103
- api_key = secrets . ZULIP_API_KEY ,
104
- site = secrets . ZULIP_URL )
102
+ self .zulip_client = zulip .Client (email = ZULIP_BOT_EMAIL ,
103
+ api_key = ZULIP_API_KEY ,
104
+ site = ZULIP_URL )
105
105
self .zulip_thread = threading .Thread (target = self .run_zulip_listener )
106
106
self .zulip_thread .setDaemon (True )
107
107
self .zulip_thread .start ()
@@ -112,10 +112,10 @@ def __init__(self):
112
112
self .user_formatter = slack_reformat .SlackUserFormatter (
113
113
lambda user_id : self .get_slack_user (user_id , web_client = self .slack_web_client ))
114
114
115
- if secrets . GROUPME_ENABLE :
115
+ if GROUPME_ENABLE :
116
116
_LOGGER .debug ('connecting to groupmes' )
117
117
self .groupme_threads = {}
118
- for channel , conf in secrets . GROUPME_TWO_WAY .items ():
118
+ for channel , conf in GROUPME_TWO_WAY .items ():
119
119
self .groupme_threads [channel ] = threading .Thread (
120
120
target = self .run_groupme_listener , args = (channel , conf ))
121
121
self .groupme_threads [channel ].setDaemon (True )
@@ -161,7 +161,7 @@ async def receive_slack_msg(**payload):
161
161
if not user_id :
162
162
_LOGGER .debug ("no bot found" )
163
163
return
164
- if user_id == secrets . SLACK_BOT_ID :
164
+ if user_id == SLACK_BOT_ID :
165
165
_LOGGER .debug ("oops that's my message!" )
166
166
return
167
167
bot = True
@@ -239,29 +239,29 @@ async def receive_slack_msg(**payload):
239
239
needs_leading_newline = \
240
240
(len (msg ) > 0 or len (formatted_attachments ['markdown' ]) > 0 )
241
241
formatted_files = slack_reformat .format_files_from_slack (
242
- files , needs_leading_newline , secrets . SLACK_TOKEN , self .zulip_client )
242
+ files , needs_leading_newline , SLACK_TOKEN , self .zulip_client )
243
243
244
244
zulip_message_text = \
245
245
msg + formatted_attachments ['markdown' ] + formatted_files ['markdown' ]
246
246
247
- if channel_name in secrets . PUBLIC_TWO_WAY :
247
+ if channel_name in PUBLIC_TWO_WAY :
248
248
self .send_to_zulip (
249
249
channel_name , zulip_message_text , user = user ,
250
250
send_public = True , slack_id = msg_id ,
251
251
edit = edit , delete = delete , me = me )
252
252
253
253
# If we are not sending publicly, then we are sending for
254
254
# logging purposes, which might be disabled.
255
- if secrets . ZULIP_LOG_ENABLE :
255
+ if ZULIP_LOG_ENABLE :
256
256
self .send_to_zulip (
257
257
channel_name , zulip_message_text , user = user ,
258
258
slack_id = msg_id , edit = edit ,
259
259
delete = delete , me = me , private = private )
260
260
261
261
# If groupme is enabled, then send there. Note that this
262
- # will also filter to only the secrets. GROUPME_TWO_WAY channels
262
+ # will also filter to only the GROUPME_TWO_WAY channels
263
263
# within the send_to_groupme call.
264
- if secrets . GROUPME_ENABLE :
264
+ if GROUPME_ENABLE :
265
265
groupme_message_text = \
266
266
msg + formatted_attachments ['plaintext' ] + formatted_files ['plaintext' ]
267
267
@@ -299,17 +299,17 @@ async def receive_slack_msg(**payload):
299
299
300
300
_LOGGER .debug ('connecting to slack' )
301
301
self .slack_loop = asyncio .new_event_loop ()
302
- self .slack_rtm_client = slack .RTMClient (token = secrets . SLACK_TOKEN ,
302
+ self .slack_rtm_client = slack .RTMClient (token = SLACK_TOKEN ,
303
303
run_async = True ,
304
304
loop = self .slack_loop )
305
- self .slack_web_client = slack .WebClient (token = secrets . SLACK_TOKEN ,
305
+ self .slack_web_client = slack .WebClient (token = SLACK_TOKEN ,
306
306
run_async = True ,
307
307
loop = self .slack_loop )
308
308
self .slack_log_format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
309
309
self .slack_log_formatter = logging .Formatter (self .slack_log_format )
310
310
self .slack_logger = SlackHandler (self .slack_web_client ,
311
311
self .slack_loop ,
312
- secrets . SLACK_ERR_CHANNEL )
312
+ SLACK_ERR_CHANNEL )
313
313
self .slack_logger .setLevel (logging .INFO )
314
314
self .slack_logger .setFormatter (self .slack_log_formatter )
315
315
logging .getLogger ('' ).addHandler (self .slack_logger )
@@ -319,8 +319,8 @@ def send_from_zulip(self, msg):
319
319
_LOGGER .debug ('caught zulip message' )
320
320
_LOGGER .debug ('JSON: %s' % json .dumps (msg ))
321
321
try :
322
- if (msg ['subject' ] in secrets . PUBLIC_TWO_WAY and
323
- msg ['sender_email' ] != secrets . ZULIP_BOT_EMAIL ):
322
+ if (msg ['subject' ] in PUBLIC_TWO_WAY and
323
+ msg ['sender_email' ] != ZULIP_BOT_EMAIL ):
324
324
_LOGGER .debug ('good to send zulip message to slack' )
325
325
asyncio .ensure_future (
326
326
self .slack_web_client .chat_postMessage (
@@ -330,7 +330,7 @@ def send_from_zulip(self, msg):
330
330
mrkdwn = True
331
331
# thread_ts=thread_ts
332
332
), loop = self .slack_loop )
333
- if secrets . GROUPME_ENABLE :
333
+ if GROUPME_ENABLE :
334
334
self .send_to_groupme (msg ['subject' ], msg ['content' ],
335
335
user = msg ['sender_full_name' ])
336
336
except :
@@ -369,7 +369,7 @@ def send_from_groupme(self, channel, conf, post_data):
369
369
mrkdwn = True
370
370
# thread_ts=thread_ts
371
371
), loop = self .slack_loop )
372
- if channel in secrets . PUBLIC_TWO_WAY :
372
+ if channel in PUBLIC_TWO_WAY :
373
373
self .send_to_zulip (channel , message_text , user = user ,
374
374
send_public = True )
375
375
channel_id = self .get_slack_channel_by_name (channel )
@@ -530,11 +530,11 @@ def send_to_zulip(self, subject, msg, user=None, slack_id=None,
530
530
elif user is not None and me :
531
531
user_prefix = '**' + user + '** '
532
532
533
- to = secrets . ZULIP_LOG_PUBLIC_STREAM
533
+ to = ZULIP_LOG_PUBLIC_STREAM
534
534
if send_public :
535
- to = secrets . PUBLIC_TWO_WAY_STREAM
535
+ to = PUBLIC_TWO_WAY_STREAM
536
536
elif private :
537
- to = secrets . ZULIP_LOG_PRIVATE_STREAM
537
+ to = ZULIP_LOG_PRIVATE_STREAM
538
538
if edit and slack_id :
539
539
redis_key = REDIS_MSG_SLACK_TO_ZULIP [to ] + slack_id
540
540
zulip_id = self .redis .get (redis_key )
@@ -595,7 +595,7 @@ def send_to_zulip(self, subject, msg, user=None, slack_id=None,
595
595
return
596
596
redis_key = REDIS_MSG_SLACK_TO_ZULIP [to ] + slack_id
597
597
self .redis .set (redis_key , sent ['id' ],
598
- ex = secrets . SLACK_EDIT_UPDATE_ZULIP_TTL )
598
+ ex = SLACK_EDIT_UPDATE_ZULIP_TTL )
599
599
except :
600
600
e = sys .exc_info ()
601
601
exc_type , exc_value , exc_traceback = e
@@ -608,11 +608,11 @@ def send_to_groupme(self, subject, msg, user=None, edit=False,
608
608
delete = False , me = False ):
609
609
try :
610
610
# Check for reasons to not send to groupme.
611
- if not secrets . GROUPME_ENABLE :
611
+ if not GROUPME_ENABLE :
612
612
_LOGGER .debug ('attempting to send to groupme but groupme is disabled' )
613
613
return
614
- elif subject not in secrets . GROUPME_TWO_WAY :
615
- _LOGGER .debug ('aborting send to groupme outside of secrets. GROUPME_TWO_WAY' )
614
+ elif subject not in GROUPME_TWO_WAY :
615
+ _LOGGER .debug ('aborting send to groupme outside of GROUPME_TWO_WAY' )
616
616
return
617
617
elif edit or delete :
618
618
_LOGGER .debug ('aborting send due to edit or delete in send_to_groupme' )
@@ -627,7 +627,7 @@ def send_to_groupme(self, subject, msg, user=None, edit=False,
627
627
elif user is not None and me :
628
628
user_prefix = user + ' '
629
629
630
- to = secrets . GROUPME_TWO_WAY [subject ]
630
+ to = GROUPME_TWO_WAY [subject ]
631
631
send_data = {
632
632
'bot_id' : to ['BOT_ID' ],
633
633
'text' : user_prefix + msg
0 commit comments