-
Notifications
You must be signed in to change notification settings - Fork 2
/
bavi.py
65 lines (49 loc) · 1.48 KB
/
bavi.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/python3
import argparse
import configparser
import logging
import sys
from bavi.bot import Bot
from bavi.module_loader import load_modules
LOG_FMT = '%(asctime)-15s [%(levelname)s] %(name)s: %(message)s'
def setup_logging(conf):
if 'log' in conf:
log_config = conf['log']
else:
log_config = None
handlers = [
logging.StreamHandler(stream=sys.stdout)
]
if not log_config:
level = logging.INFO
filename = None
logging.warn('Missing logging configuration; defaulting to stdout')
else:
filename = log_config.get('file')
if filename:
handlers.append(logging.FileHandler(
filename=filename,
mode='a',
encoding='utf8'
))
level = log_config.get('level')
if level not in {'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}:
raise ValueError('Unknown log level: {}'.format(level))
level = getattr(logging, level)
logging.basicConfig(
level=level,
format=LOG_FMT,
handlers=handlers
)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='General-purpose chat bot')
parser.add_argument('-c', '--config', required=True)
args = parser.parse_args()
conf = configparser.ConfigParser()
conf.read(args.config)
setup_logging(conf)
bot = Bot(conf)
bot.init_irc()
bot.init_db()
load_modules(bot)
bot.start()