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
|
2014-04-30 20:16:16 +00:00
|
|
|
import traceback
|
2010-02-22 23:24:01 +00:00
|
|
|
import time
|
2008-06-09 11:59:56 +00:00
|
|
|
|
2009-04-18 00:57:18 +00:00
|
|
|
|
2008-06-09 11:59:56 +00:00
|
|
|
class Bot(object):
|
2014-04-30 20:16:16 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.conns = {}
|
|
|
|
self.persist_dir = os.path.abspath('persist')
|
|
|
|
if not os.path.exists(self.persist_dir):
|
2014-05-01 03:12:28 +00:00
|
|
|
os.mkdir(self.persist_dir)
|
2009-10-17 01:36:02 +00:00
|
|
|
|
2015-01-23 18:57:43 +00:00
|
|
|
bot = Bot()
|
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
def main():
|
|
|
|
sys.path += ['plugins'] # so 'import hook' works without duplication
|
|
|
|
sys.path += ['lib']
|
|
|
|
os.chdir(sys.path[0] or '.') # do stuff relative to the install directory
|
|
|
|
|
|
|
|
print 'Loading plugins'
|
2008-06-09 11:59:56 +00:00
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
# bootstrap the reloader
|
|
|
|
eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
|
2015-01-23 18:57:43 +00:00
|
|
|
os.path.join('core', 'reload.py'), 'exec'),
|
|
|
|
globals())
|
2015-01-22 07:16:27 +00:00
|
|
|
reload(init=True)
|
2009-03-15 04:14:07 +00:00
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
print 'Connecting to IRC'
|
2009-03-16 04:30:46 +00:00
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
try:
|
|
|
|
config()
|
|
|
|
if not hasattr(bot, 'config'):
|
|
|
|
exit()
|
|
|
|
except Exception, e:
|
|
|
|
print 'ERROR: malformed config file:', e
|
|
|
|
traceback.print_exc()
|
|
|
|
sys.exit()
|
2009-04-19 11:18:27 +00:00
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
print 'Running main loop'
|
2010-03-27 08:42:27 +00:00
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
while True:
|
|
|
|
reload() # these functions only do things
|
|
|
|
config() # if changes have occured
|
2008-06-09 11:59:56 +00:00
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
for conn in bot.conns.itervalues():
|
|
|
|
try:
|
|
|
|
out = conn.out.get_nowait()
|
|
|
|
main(conn, out)
|
|
|
|
except Queue.Empty:
|
|
|
|
pass
|
|
|
|
while all(conn.out.empty() for conn in bot.conns.itervalues()):
|
|
|
|
time.sleep(.1)
|
2009-11-18 00:19:26 +00:00
|
|
|
|
2015-01-22 07:16:27 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|