diff --git a/statusbot/bot.py b/statusbot/bot.py index 1a13feb..c830913 100644 --- a/statusbot/bot.py +++ b/statusbot/bot.py @@ -20,8 +20,9 @@ [ircbot] nick=NICKNAME pass=PASSWORD -server=irc.freenode.net +server=irc.oftc.net port=6697 +use_sasl=False channels=foo,bar nicks=alice,bob @@ -313,12 +314,12 @@ class AlertFile(UpdateInterface): self.write(None) -class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot): +class BaseStatusBot(SSL, irc.bot.SingleServerIRCBot): log = logging.getLogger("statusbot.bot") def __init__(self, channels, nicks, publishers, successlog, thankslog, nickname, password, server, port=6697): - super(StatusBot, self).__init__( + super(BaseStatusBot, self).__init__( server_list=[(server, port)], nickname=nickname, realname=nickname, @@ -328,33 +329,15 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot): self.nicks = nicks self.nickname = nickname self.password = password - self.identify_msg_cap = False self.topics = {} self.current_topic = None self.publishers = publishers self.successlog = successlog self.thankslog = thankslog - def on_welcome(self, c, e): - self.identify_msg_cap = False - self.log.debug("Requesting identify-msg capability") - c.cap('REQ', 'identify-msg') - c.cap('END') - - def on_cap(self, c, e): - self.log.debug("Received cap response %s" % repr(e.arguments)) - if e.arguments[0] == 'ACK' and 'identify-msg' in e.arguments[1]: - self.log.debug("identify-msg cap acked") - self.identify_msg_cap = True - def on_pubmsg(self, c, e): - if not self.identify_msg_cap: - self.log.debug("Ignoring message because identify-msg " - "cap not enabled") - return nick = e.source.split('!')[0] - auth = e.arguments[0][0] - msg = e.arguments[0][1:] + msg = e.arguments[0] # Unprivileged commands if msg.startswith('#success'): self.handle_success_command(e.target, nick, msg) @@ -365,10 +348,6 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot): # Privileged commands if not msg.startswith('#status'): return - if auth != '+': - self.log.debug("Ignoring message from unauthenticated " - "user %s" % nick) - return if nick not in self.nicks: self.log.debug("Ignoring message from untrusted user %s" % nick) return @@ -474,6 +453,29 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot): time.sleep(ANTI_FLOOD_SLEEP) +class NoSASLStatusBot(BaseStatusBot): + def on_welcome(self, c, e): + self.log.debug("Identifying to nickserv") + c.privmsg("nickserv", "identify %s " % self.password) + for channel in self.channel_list: + self.log.info("Joining %s" % channel) + c.join(channel) + time.sleep(ANTI_FLOOD_SLEEP) + + def on_nicknameinuse(self, c, e): + self.log.debug("Nickname in use, releasing") + c.nick(c.get_nickname() + "_") + c.privmsg("nickserv", "identify %s " % self.password) + c.privmsg("nickserv", "ghost %s %s" % (self.nickname, self.password)) + c.privmsg("nickserv", "release %s %s" % (self.nickname, self.password)) + time.sleep(ANTI_FLOOD_SLEEP) + c.nick(self.nickname) + + +class SASLStatusBot(SASL, BaseStatusBot): + pass + + def _main(configpath): config = ConfigParser.RawConfigParser() config.read(configpath) @@ -490,11 +492,24 @@ def _main(configpath): if config.has_section('twitter'): publishers.append(Tweet(config)) - bot = StatusBot(channels, nicks, publishers, successlog, thankslog, - config.get('ircbot', 'nick'), - config.get('ircbot', 'pass'), - config.get('ircbot', 'server'), - config.getint('ircbot', 'port')) + if config.has_option('ircbot', 'use_sasl'): + use_sasl = config.getboolean('ircbot', 'use_sasl') + else: + use_sasl = False + if use_sasl: + bot = SASLStatusBot(channels, nicks, publishers, successlog, + thankslog, + config.get('ircbot', 'nick'), + config.get('ircbot', 'pass'), + config.get('ircbot', 'server'), + config.getint('ircbot', 'port')) + else: + bot = NoSASLStatusBot(channels, nicks, publishers, successlog, + thankslog, + config.get('ircbot', 'nick'), + config.get('ircbot', 'pass'), + config.get('ircbot', 'server'), + config.getint('ircbot', 'port')) bot.start()