-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
45 lines (36 loc) · 1.31 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
import sys, ConfigParser
from twisted.internet import reactor, ssl
from LockBot import LockBotFactory
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.stderr.write("You should pass only one argument "
"(configuration path)\n")
sys.exit(1)
cfgpath = sys.argv[1]
section='lockbot'
defaultcfg = {'usessl' : 'no',
'nickname': 'lockbot'}
cfg = ConfigParser.RawConfigParser(defaultcfg)
cfg.read(cfgpath)
usessl = cfg.getboolean(section, 'usessl')
server = cfg.get(section, 'server')
port = cfg.getint(section, 'port')
channel = cfg.get(section, 'channel')
nickname = cfg.get(section, 'nickname')
dbdir = cfg.get(section, 'dbdir')
password = cfg.get(section, 'password')
lockbotfactory = LockBotFactory('#' + channel,
nickname,
dbdir,
password=password)
connectfn = reactor.connectTCP
connectargs = []
connectargs.append(server)
connectargs.append(port)
connectargs.append(lockbotfactory)
if usessl:
connectfn = reactor.connectSSL
connectargs.append(ssl.ClientContextFactory())
connectargs = tuple(connectargs)
connectfn(*connectargs)
reactor.run()