-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (44 loc) · 1.55 KB
/
Copy pathmain.py
File metadata and controls
59 lines (44 loc) · 1.55 KB
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
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""Local development entrypoint. Production is served by wsgi.py under gunicorn."""
import logging
import sys
from concurrent.futures import ThreadPoolExecutor
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
import config
from commands import add_all, ping
from events import channels, mentions
from utils.autojoin import join_all_public_channels_async
REGISTRARS = (ping, add_all, channels, mentions)
log = logging.getLogger(__name__)
def build_app():
app = App(
token=config.BOT_TOKEN,
signing_secret=config.SIGNING_SECRET,
# Handlers keep making blocking Slack API calls after ack(); bolt's
# default pool of 5 starves once an /add-all invite loop takes a thread.
listener_executor=ThreadPoolExecutor(max_workers=10),
)
for module in REGISTRARS:
module.register(app)
return app
def configure_logging():
sys.stdout.reconfigure(line_buffering=True)
sys.stderr.reconfigure(line_buffering=True)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)-7s %(name)s: %(message)s",
)
def main():
configure_logging()
app = build_app()
if config.AUTOJOIN_ON_BOOT:
join_all_public_channels_async(app.client)
if config.APP_TOKEN:
log.info("Starting in Socket Mode")
SocketModeHandler(app, config.APP_TOKEN).start()
else:
log.info("Starting HTTP server on port %d", config.PORT)
app.start(port=config.PORT)
if __name__ == "__main__":
main()