-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot
More file actions
43 lines (34 loc) · 1.21 KB
/
bot
File metadata and controls
43 lines (34 loc) · 1.21 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
#!/usr/bin/env python3
# vim: noai:ts=4:sw=4:expandtab:syntax=python
import xbotpp
import io
import re
import argparse
from configparser import ConfigParser
default_cfg = io.StringIO("""\
[bot]
prefix = '
""")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", metavar="FILE", help="read configuration from FILE", default="xbotpp.conf")
parser.add_argument("-n", "--network", metavar="NETWORK", help="connect to the network named NETWORK")
options = parser.parse_args()
config = ConfigParser()
config.readfp(default_cfg)
config.module_path = 'modules'
if config.read(options.config):
network = None
if options.network:
network = "network: " + options.network
else:
for conf in config.__dict__['_sections']:
possible_network = re.match('^network:(.*?)$', conf)
if possible_network:
network = possible_network.group(0).strip()
if network:
config.active_network = network
bot = xbotpp.Bot(config)
bot.start()
else:
print("Error: could not read configuration %s." % options.config, file=sys.stderr)