2008-06-09 11:59:56 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2009-03-15 03:06:36 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import Queue
|
2008-06-09 11:59:56 +00:00
|
|
|
|
2009-04-17 03:52:47 +00:00
|
|
|
sys.path += ['plugins'] # so 'import hook' works without duplication
|
2009-07-05 14:52:17 +00:00
|
|
|
sys.path += ['lib']
|
2009-04-19 11:42:48 +00:00
|
|
|
os.chdir(sys.path[0]) # do stuff relative to the installation directory
|
2009-04-17 03:52:47 +00:00
|
|
|
|
2009-04-18 00:57:18 +00:00
|
|
|
|
2008-06-09 11:59:56 +00:00
|
|
|
class Bot(object):
|
2009-04-19 11:18:27 +00:00
|
|
|
pass
|
2009-04-18 00:57:18 +00:00
|
|
|
|
2009-10-17 01:36:02 +00:00
|
|
|
|
2009-04-19 11:18:27 +00:00
|
|
|
bot = Bot()
|
2008-06-09 11:59:56 +00:00
|
|
|
|
|
|
|
print 'Loading plugins'
|
2009-03-15 04:14:07 +00:00
|
|
|
|
2009-04-19 11:18:27 +00:00
|
|
|
# bootstrap the reloader
|
|
|
|
eval(compile(open('core/reload.py', 'U').read(), 'core/reload.py', 'exec'))
|
2009-10-17 01:36:02 +00:00
|
|
|
reload(init=True)
|
2009-03-16 04:30:46 +00:00
|
|
|
|
2008-06-09 11:59:56 +00:00
|
|
|
print 'Connecting to IRC'
|
2009-04-19 11:18:27 +00:00
|
|
|
|
2009-11-18 00:19:26 +00:00
|
|
|
bot.conns = {}
|
|
|
|
|
2009-11-18 00:27:55 +00:00
|
|
|
try:
|
|
|
|
for connection in bot.config['connections']:
|
|
|
|
for name, conf in connection.iteritems():
|
|
|
|
if name in bot.conns:
|
|
|
|
print 'ERROR: more than one connection named "%s"' % name
|
|
|
|
raise ValueError
|
2009-11-18 00:38:48 +00:00
|
|
|
bot.conns[name] = irc(conf['server'], conf['nick'],
|
2009-11-19 04:32:28 +00:00
|
|
|
channels=conf['channels'], conf=conf)
|
2009-11-18 00:27:55 +00:00
|
|
|
except Exception, e:
|
|
|
|
print 'ERROR: malformed config file', Exception, e
|
|
|
|
sys.exit()
|
2009-11-18 00:38:48 +00:00
|
|
|
|
2009-04-03 03:50:38 +00:00
|
|
|
bot.persist_dir = os.path.abspath('persist')
|
2008-06-09 11:59:56 +00:00
|
|
|
|
|
|
|
print 'Running main loop'
|
|
|
|
|
|
|
|
while True:
|
2009-04-18 00:57:18 +00:00
|
|
|
try:
|
2009-11-18 00:19:26 +00:00
|
|
|
reload() # these functions only do things
|
|
|
|
config() # if changes have occured
|
|
|
|
|
|
|
|
for conn in bot.conns.itervalues():
|
|
|
|
out = conn.out.get(timeout=1)
|
|
|
|
main(conn, out)
|
2008-06-09 11:59:56 +00:00
|
|
|
except Queue.Empty:
|
|
|
|
pass
|