-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
31 lines (30 loc) · 1.03 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
import json
import sys
from oyoyo.client import IRCClient
from constants import SETTINGS_FILE
from handler import KevinBotCommandHandler
# Main program
if __name__ == '__main__':
try:
f = open(SETTINGS_FILE, 'r')
settings = json.load(f)
except (IOError, ValueError):
print >> sys.stderr,\
('File %s is missing or unreadable, or has an invalid format' %
SETTINGS_FILE)
exit(1)
finally:
f.close()
# HACK: IRCClient.__init__ is expecting a class name that it can use to
# construct a new handler object. This lambda expression allows us to
# pass parameters to the handler's constructor, avoiding the need for
# global variables.
cli = IRCClient(lambda client: KevinBotCommandHandler(client, settings),
host = settings['host'],
port = settings['port'],
nick = settings['nick'],
blocking = True)
conn = cli.connect()
while True:
conn.next()
print 'Exiting.'