2010-03-19 05:20:00 +00:00
|
|
|
#!/usr/bin/env python
|
2008-06-09 11:59:56 +00:00
|
|
|
|
2009-03-15 03:06:36 +00:00
|
|
|
import os
|
|
|
|
import Queue
|
2010-02-22 23:24:01 +00:00
|
|
|
import sys
|
|
|
|
import time
|
2008-06-09 11:59:56 +00:00
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
sys.path += ['plugins'] # so 'import hook' works without duplication
|
2009-07-05 14:52:17 +00:00
|
|
|
sys.path += ['lib']
|
2010-03-01 02:32:41 +00:00
|
|
|
os.chdir(sys.path[0] or '.') # do stuff relative to the install 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
|
2010-03-01 02:32:41 +00:00
|
|
|
eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
|
2010-01-17 20:38:37 +00:00
|
|
|
os.path.join('core', 'reload.py'), 'exec'))
|
2009-10-17 01:36:02 +00:00
|
|
|
reload(init=True)
|
2009-03-16 04:30:46 +00:00
|
|
|
|
2010-05-07 23:16:44 +00:00
|
|
|
config()
|
|
|
|
if not hasattr(bot, 'config'):
|
|
|
|
exit()
|
|
|
|
|
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:
|
2010-02-23 03:32:09 +00:00
|
|
|
for name, conf in bot.config['connections'].iteritems():
|
|
|
|
if conf.get('ssl'):
|
2010-03-01 02:32:41 +00:00
|
|
|
bot.conns[name] = SSLIRC(conf['server'], conf['nick'], conf=conf,
|
|
|
|
port=conf.get('port', 6667), channels=conf['channels'],
|
2010-02-23 03:32:09 +00:00
|
|
|
ignore_certificate_errors=conf.get('ignore_cert', True))
|
|
|
|
else:
|
2010-03-01 02:32:41 +00:00
|
|
|
bot.conns[name] = IRC(conf['server'], conf['nick'], conf=conf,
|
|
|
|
port=conf.get('port', 6667), channels=conf['channels'])
|
2009-11-18 00:27:55 +00:00
|
|
|
except Exception, e:
|
2010-05-07 23:16:44 +00:00
|
|
|
print 'ERROR: malformed config file', e
|
2009-11-18 00:27:55 +00:00
|
|
|
sys.exit()
|
2010-03-27 08:42:27 +00:00
|
|
|
|
2009-04-03 03:50:38 +00:00
|
|
|
bot.persist_dir = os.path.abspath('persist')
|
2010-01-18 17:47:55 +00:00
|
|
|
if not os.path.exists(bot.persist_dir):
|
|
|
|
os.mkdir(bot.persist_dir)
|
2008-06-09 11:59:56 +00:00
|
|
|
|
|
|
|
print 'Running main loop'
|
|
|
|
|
|
|
|
while True:
|
2010-03-01 02:32:41 +00:00
|
|
|
reload() # these functions only do things
|
|
|
|
config() # if changes have occured
|
2009-11-18 00:19:26 +00:00
|
|
|
|
2010-02-22 23:24:01 +00:00
|
|
|
for conn in bot.conns.itervalues():
|
|
|
|
try:
|
|
|
|
out = conn.out.get_nowait()
|
2010-02-22 23:49:30 +00:00
|
|
|
main(conn, out)
|
2010-02-22 23:24:01 +00:00
|
|
|
except Queue.Empty:
|
|
|
|
pass
|
|
|
|
while all(conn.out.empty() for conn in bot.conns.itervalues()):
|
2010-03-11 23:34:54 +00:00
|
|
|
time.sleep(.1)
|