#!/usr/bin/env python2.6 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): # user modes # TODO: config file connection.mode(nick, '-x') # join the specified channel # TODO: support multiple if irclib.is_channel(channel): connection.join(channel) ##### # init ##### # read config file config = ConfigParser({'debug': 'false'}) config.read([os.path.expanduser('~/.dr.botzo.cfg'), 'dr.botzo.cfg']) # load necessary options try: # load connection info server = config.get('IRC', 'server') port = config.getint('IRC', 'port') channel = config.get('IRC', 'channel') nick = config.get('IRC', 'nick') ircname = config.get('IRC', 'name') except NoSectionError as e: sys.exit("Aborted due to error with necessary configuration: " + str(e)) except NoOptionError as e: sys.exit("Aborted due to error with necessary configuration: " + str(e)) # load additional options irclib.DEBUG = config.getboolean('IRC', 'debug') # 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