forked from pajbot/pajbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·65 lines (44 loc) · 1.34 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import logging
import os
import signal
import sys
from pajbot.bot import Bot
try:
basestring
except NameError:
basestring = str
# XXX: What does this achieve exactly?
os.chdir(os.path.dirname(os.path.realpath(__file__)))
log = logging.getLogger(__name__)
def run(args):
from pajbot.utils import load_config
config = load_config(args.config)
if 'main' not in config:
log.error('Missing section [main] in config')
sys.exit(1)
if 'sql' in config:
log.error('The [sql] section in config is no longer used. See config.example.ini for the new format under [main].')
sys.exit(1)
if 'db' not in config['main']:
log.error('Missing required db config in the [main] section.')
sys.exit(1)
pajbot = Bot(config, args)
pajbot.connect()
def on_sigterm(signal, frame):
pajbot.quit_bot()
sys.exit(0)
signal.signal(signal.SIGTERM, on_sigterm)
try:
pajbot.start()
except KeyboardInterrupt:
pajbot.quit_bot()
pass
def handle_exceptions(exctype, value, tb):
log.error('Logging an uncaught exception', exc_info=(exctype, value, tb))
if __name__ == '__main__':
from pajbot.utils import init_logging
sys.excepthook = handle_exceptions
args = Bot.parse_args()
init_logging('pajbot')
run(args)