From 7da1834e6ab3096ea546bb6f241ac458229fc333 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Wed, 18 Nov 2009 21:32:28 -0700 Subject: [PATCH] split more irc stuff from core into plugins, add nickserv support --- bot.py | 4 +--- core/irc.py | 11 +++++++---- plugins/misc.py | 25 ++++++++++++++++++++----- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/bot.py b/bot.py index 12a4c8f..096c74e 100755 --- a/bot.py +++ b/bot.py @@ -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() diff --git a/core/irc.py b/core/irc.py index f2fea6d..9c6b001 100644 --- a/core/irc.py +++ b/core/irc.py @@ -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): diff --git a/plugins/misc.py b/plugins/misc.py index 9943d45..614df7e 100644 --- a/plugins/misc.py +++ b/plugins/misc.py @@ -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)