h/bot.py

51 lines
860 B
Python
Raw Normal View History

2008-06-09 11:59:56 +00:00
#!/usr/bin/python
2009-03-15 06:51:39 +00:00
network = "irc.synirc.net"
nick = "skybot"
channel = "#cobol"
2008-06-09 11:59:56 +00:00
2009-03-15 03:06:36 +00:00
import sys
import os
import glob
import re
import thread
import Queue
import collections
2008-06-09 11:59:56 +00:00
sys.path += ['plugins'] # so 'import hook' works without duplication
2009-03-15 03:06:36 +00:00
import irc
import yaml
2008-06-09 11:59:56 +00:00
2009-03-16 04:51:06 +00:00
os.chdir(sys.path[0]) # do stuff relative to the installation directory
2008-06-09 11:59:56 +00:00
2008-06-09 11:59:56 +00:00
class Bot(object):
pass
bot = Bot()
2008-06-09 11:59:56 +00:00
print 'Loading plugins'
2009-03-15 04:14:07 +00:00
# bootstrap the reloader
eval(compile(open('core/reload.py', 'U').read(), 'core/reload.py', 'exec'))
2008-06-09 11:59:56 +00:00
print 'Connecting to IRC'
bot.nick = nick
bot.channel = channel
bot.network = network
2009-03-15 06:51:39 +00:00
bot.irc = irc.irc(network, nick)
2008-06-09 11:59:56 +00:00
bot.irc.join(channel)
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:
try:
2008-06-09 11:59:56 +00:00
out = bot.irc.out.get(timeout=1)
reload()
main(out)
2008-06-09 11:59:56 +00:00
except Queue.Empty:
pass