basic irc connection code
This commit is contained in:
parent
a6ba5ef40c
commit
500f689774
27
dr.botzo.py
27
dr.botzo.py
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue