dr.botzo/dr.botzo.py

58 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python2.6
2010-07-24 09:54:38 -05:00
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
2010-07-24 09:54:38 -05:00
import os
import sys
2010-07-24 09:54:38 -05:00
2010-07-24 10:47:33 -05:00
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')
2010-07-24 10:47:33 -05:00
# join the specified channel
# TODO: support multiple
if irclib.is_channel(channel):
connection.join(channel)
#####
# init
#####
# read config file
2010-07-24 11:34:19 -05:00
config = ConfigParser({'debug': 'false'})
2010-07-24 09:54:38 -05:00
config.read([os.path.expanduser('~/.dr.botzo.cfg'), 'dr.botzo.cfg'])
2010-07-24 11:34:19 -05:00
# 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))
2010-07-24 09:54:38 -05:00
2010-07-24 11:34:19 -05:00
# load additional options
irclib.DEBUG = config.getboolean('IRC', 'debug')
2010-07-24 10:47:33 -05:00
# 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()
2010-07-24 09:54:38 -05:00
# vi:tabstop=4:expandtab:autoindent