-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
49 lines (38 loc) · 1.49 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime
from subprocess import check_output
from slack_bolt.adapter.socket_mode import SocketModeHandler
from shared import *
for feat in config['features_enabled']:
exec(f"import {feat}")
print("Starting parrotbot...", flush=True, file=info_stream)
@app.command("/parrotcheckhealth")
def parrotcheckhealth(client, ack, body, say):
MAX_CHARS=2500
log = check_output(config['log']['command'], shell=True, text=True).replace('files.slack.com', '********')
log_lines = log.split('\n')
log_messages = []
# incredibly jank but whatever
while len(log_lines) > 0:
msg = ""
while len(log_lines) > 0 and len(msg) + len(log_lines[0]) <= MAX_CHARS:
msg += log_lines.pop(0) + '\n'
log_messages.append(msg)
if "quiet" in body['text']:
ack("I'm running! Here is my latest log:" \
"\n```\n" + log_messages[-1] + '```')
else:
say("I'm running! Here is my log:")
for msg in log_messages:
say("\n```\n" + msg + '```', unfurl_media = False, unfurl_links=False)
ack()
if __name__ == "__main__":
# why no do while python??
cursor = None
while cursor != '':
conversations = app.client.conversations_list(cursor=cursor)
for chan in conversations['channels']:
if not (chan['is_im'] or chan['is_member'] or chan['is_archived']):
app.client.conversations_join(channel=chan['id'])
print(f"Joined {chan['name']}", flush=True, file=info_stream)
cursor = conversations['response_metadata']['next_cursor']
SocketModeHandler(app, config['slack_app_token']).start()