split more irc stuff from core into plugins, add nickserv support

This commit is contained in:
Ryan Hitchman 2009-11-18 21:32:28 -07:00
parent d44223399f
commit 7da1834e6a
3 changed files with 28 additions and 12 deletions

4
bot.py
View File

@ -32,9 +32,7 @@ try:
print 'ERROR: more than one connection named "%s"' % name
raise ValueError
bot.conns[name] = irc(conf['server'], conf['nick'],
channels=conf['channels'])
for channel in conf['channels']:
bot.conns[name].join(channel)
channels=conf['channels'], conf=conf)
except Exception, e:
print 'ERROR: malformed config file', Exception, e
sys.exit()

View File

@ -61,17 +61,20 @@ irc_param_ref = re.compile(r'(?:^|(?<= ))(:.*|[^ ]+)').findall
class irc(object):
"handles the IRC protocol"
#see the docs/ folder for more information on the protocol
def __init__(self, server, nick, port=6667, channels=[]):
self.server = server
self.conn = crlf_tcp(server, port)
def __init__(self, server, nick, port=6667, channels=[], conf={}):
self.channels = channels
self.conf = conf
self.server = server
self.conn = crlf_tcp(server, port)
thread.start_new_thread(self.conn.run, ())
self.out = Queue.Queue() #responses from the server are placed here
# format: [rawline, prefix, command, params,
# nick, user, host, paramlist, msg]
self.nick = nick
self.set_nick(nick)
self.cmd("USER", ["skybot v0.01", "0", "bot"])
self.cmd("USER", ["skybot", "3", "*",
":Python bot - http://bitbucket.org/Scaevolus/skybot/"])
thread.start_new_thread(self.parse_loop, ())
def parse_loop(self):

View File

@ -1,12 +1,27 @@
from util import hook
@hook.event('KICK INVITE')
#autorejoin channels
@hook.event('KICK')
def rejoin(bot, input):
if input.command == 'KICK':
if input.paraml[1] == input.conn.nick:
if input.paraml[0] in input.conn.channels:
input.conn.join(input.paraml[0])
if input.paraml[1] == input.conn.nick:
if input.paraml[0] in input.conn.channels:
input.conn.join(input.paraml[0])
#join channels when invited
@hook.event('INVITE')
def invite(bot, input):
if input.command == 'INVITE':
input.conn.join(input.inp)
#join channels when server says hello & identify bot
@hook.event('004')
def onjoin(bot, input):
for channel in input.conn.channels:
input.conn.join(channel)
nickserv_password = input.conn.conf.get('nickserv_password', '')
nickserv_name = input.conn.conf.get('nickserv_name', 'nickserv')
nickserv_command = input.conn.conf.get('nickserv_command', 'IDENTIFY %s')
if nickserv_password:
input.conn.msg(nickserv_name, nickserv_command % nickserv_password)