First :D
This commit is contained in:
commit
37588421f3
100 changed files with 22673 additions and 0 deletions
64
bot.py
Normal file
64
bot.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import Queue
|
||||
import sys
|
||||
import time
|
||||
|
||||
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
|
||||
|
||||
|
||||
class Bot(object):
|
||||
pass
|
||||
|
||||
|
||||
bot = Bot()
|
||||
|
||||
print 'Loading plugins'
|
||||
|
||||
# bootstrap the reloader
|
||||
eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
|
||||
os.path.join('core', 'reload.py'), 'exec'))
|
||||
reload(init=True)
|
||||
|
||||
config()
|
||||
if not hasattr(bot, 'config'):
|
||||
exit()
|
||||
|
||||
print 'Connecting to IRC'
|
||||
|
||||
bot.conns = {}
|
||||
|
||||
try:
|
||||
for name, conf in bot.config['connections'].iteritems():
|
||||
if conf.get('ssl'):
|
||||
bot.conns[name] = SSLIRC(conf['server'], conf['nick'], conf=conf,
|
||||
port=conf.get('port', 6667), channels=conf['channels'],
|
||||
ignore_certificate_errors=conf.get('ignore_cert', True))
|
||||
else:
|
||||
bot.conns[name] = IRC(conf['server'], conf['nick'], conf=conf,
|
||||
port=conf.get('port', 6667), channels=conf['channels'])
|
||||
except Exception, e:
|
||||
print 'ERROR: malformed config file', e
|
||||
sys.exit()
|
||||
|
||||
bot.persist_dir = os.path.abspath('persist')
|
||||
if not os.path.exists(bot.persist_dir):
|
||||
os.mkdir(bot.persist_dir)
|
||||
|
||||
print 'Running main loop'
|
||||
|
||||
while True:
|
||||
reload() # these functions only do things
|
||||
config() # if changes have occured
|
||||
|
||||
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)
|
Reference in a new issue