From 126c90b997210c4e470ee7918ec6a0cc0c8fdfd0 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Fri, 28 May 2021 13:04:04 -0700 Subject: [PATCH] Add non SASL auth back to statusbot Some networks don't support SASL and we want to support those networks. This adds non SASL auth back to this IRC bot. Note that we have an issue with the identify-msg capability being required by statusbot but we need a workaround for on networks like OFTC. Change-Id: I81381398b4c100990c04f454191cee52568dbdfe --- statusbot/bot.py | 56 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/statusbot/bot.py b/statusbot/bot.py index 1a13feb..2c2f3c4 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, @@ -337,6 +338,7 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot): def on_welcome(self, c, e): self.identify_msg_cap = False + # TODO what do we do about this capability request? self.log.debug("Requesting identify-msg capability") c.cap('REQ', 'identify-msg') c.cap('END') @@ -348,6 +350,7 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot): self.identify_msg_cap = True def on_pubmsg(self, c, e): + # TODO see TODO in on_welcome if not self.identify_msg_cap: self.log.debug("Ignoring message because identify-msg " "cap not enabled") @@ -474,6 +477,30 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot): time.sleep(ANTI_FLOOD_SLEEP) +class NoSASLStatusBot(BaseStatusBot): + def on_welcome(self, c, e): + super(NoSASLStatusBot, self).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 +517,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()