basic irc connection code

This commit is contained in:
Brian S. Stephan 2010-07-24 10:47:33 -05:00
parent a6ba5ef40c
commit 500f689774
1 changed files with 27 additions and 0 deletions

View File

@ -4,6 +4,21 @@ from ConfigParser import ConfigParser, NoSectionError, NoOptionError
import os
import sys
import irclib
# handler for when the bot has connected to IRC
def on_connect(connection, event):
# join the specified channel
# TODO: support multiple
if irclib.is_channel(channel):
connection.join(channel)
#####
# init
#####
# read config file
config = ConfigParser()
config.read([os.path.expanduser('~/.dr.botzo.cfg'), 'dr.botzo.cfg'])
@ -19,4 +34,16 @@ except NoSectionError as e:
except NoOptionError as e:
sys.exit("Aborted due to error with necessary configuration: " + str(e))
# start up the IRC bot
# create IRC and server objects and connect
irc = irclib.IRC()
server = irc.server().connect(server, port, nick, ircname)
# install handlers
server.add_global_handler("welcome", on_connect)
# loop forever
irc.process_forever()
# vi:tabstop=4:expandtab:autoindent