2011-11-20 10:23:31 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import Queue
|
|
|
|
import sys
|
|
|
|
import time
|
2013-07-31 16:33:27 +02:00
|
|
|
import re
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2013-10-01 06:33:48 +02:00
|
|
|
sys.path += ['plugins', 'lib'] # add stuff to the sys.path for easy imports
|
2011-11-20 10:23:31 +01:00
|
|
|
os.chdir(sys.path[0] or '.') # do stuff relative to the install directory
|
|
|
|
|
|
|
|
|
|
|
|
class Bot(object):
|
|
|
|
pass
|
|
|
|
|
2013-10-01 06:33:48 +02:00
|
|
|
print 'CloudBot DEV <http://git.io/cloudbotirc>'
|
2013-09-04 12:16:57 +02:00
|
|
|
|
2013-10-01 06:33:48 +02:00
|
|
|
# create new bot object
|
2011-11-20 10:23:31 +01:00
|
|
|
bot = Bot()
|
2013-08-02 00:58:59 +02:00
|
|
|
bot.vars = {}
|
2013-10-01 06:33:48 +02:00
|
|
|
|
|
|
|
# record start time for the uptime command
|
2012-04-01 21:05:27 +02:00
|
|
|
bot.start_time = time.time()
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2013-10-01 06:33:48 +02:00
|
|
|
print 'Begin Plugin Loading.'
|
2011-11-20 10:23:31 +01:00
|
|
|
|
|
|
|
# bootstrap the reloader
|
|
|
|
eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
|
2013-09-04 12:16:57 +02:00
|
|
|
os.path.join('core', 'reload.py'), 'exec'))
|
2011-11-20 10:23:31 +01:00
|
|
|
reload(init=True)
|
|
|
|
|
|
|
|
config()
|
|
|
|
if not hasattr(bot, 'config'):
|
|
|
|
exit()
|
|
|
|
|
2012-04-02 17:22:13 +02:00
|
|
|
print 'Connecting to IRC...'
|
2011-11-20 10:23:31 +01:00
|
|
|
|
|
|
|
bot.conns = {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
for name, conf in bot.config['connections'].iteritems():
|
2013-07-31 16:33:27 +02:00
|
|
|
# strip all spaces and capitalization from the connection name
|
|
|
|
name = name.replace(" ", "_")
|
2013-07-31 16:34:25 +02:00
|
|
|
name = re.sub('[^A-Za-z0-9_]+', '', name)
|
2012-05-09 01:13:32 +02:00
|
|
|
print 'Connecting to server: %s' % conf['server']
|
2011-11-20 10:23:31 +01:00
|
|
|
if conf.get('ssl'):
|
2012-05-07 00:56:56 +02:00
|
|
|
bot.conns[name] = SSLIRC(name, conf['server'], conf['nick'], conf=conf,
|
2013-09-04 12:16:57 +02:00
|
|
|
port=conf.get('port', 6667), channels=conf['channels'],
|
|
|
|
ignore_certificate_errors=conf.get('ignore_cert', True))
|
2011-11-20 10:23:31 +01:00
|
|
|
else:
|
2012-05-07 00:56:56 +02:00
|
|
|
bot.conns[name] = IRC(name, conf['server'], conf['nick'], conf=conf,
|
2013-09-04 12:16:57 +02:00
|
|
|
port=conf.get('port', 6667), channels=conf['channels'])
|
2012-05-09 01:13:32 +02:00
|
|
|
except Exception as e:
|
2011-11-20 10:23:31 +01:00
|
|
|
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)
|
|
|
|
|
2012-05-09 01:13:32 +02:00
|
|
|
print 'Connection(s) made, starting main loop.'
|
2011-11-20 10:23:31 +01:00
|
|
|
|
|
|
|
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)
|