Browse Source

Try not to join channels before NickServ auth has completed.

tags/v0.3
Ben Kurtovic 9 years ago
parent
commit
fc0bff62a5
2 changed files with 29 additions and 8 deletions
  1. +4
    -3
      earwigbot/irc/data.py
  2. +25
    -5
      earwigbot/irc/frontend.py

+ 4
- 3
earwigbot/irc/data.py View File

@@ -55,15 +55,16 @@ class Data(object):
self._reply_nick = self._nick self._reply_nick = self._nick
self._chan = self.line[2] self._chan = self.line[2]


if self._msgtype == "PRIVMSG":
if self._msgtype in ["PRIVMSG", "NOTICE"]:
if self.chan.lower() == self.my_nick: if self.chan.lower() == self.my_nick:
# This is a privmsg to us, so set 'chan' as the nick of the # This is a privmsg to us, so set 'chan' as the nick of the
# sender instead of the 'channel', which is ourselves: # sender instead of the 'channel', which is ourselves:
self._chan = self._nick self._chan = self._nick
self._is_private = True self._is_private = True
self._msg = " ".join(self.line[3:])[1:] self._msg = " ".join(self.line[3:])[1:]
self._parse_args()
self._parse_kwargs()
if self._msgtype == "PRIVMSG":
self._parse_args()
self._parse_kwargs()


def _parse_args(self): def _parse_args(self):
"""Parse command arguments from the message. """Parse command arguments from the message.


+ 25
- 5
earwigbot/irc/frontend.py View File

@@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.


from time import sleep

from earwigbot.irc import IRCConnection, Data from earwigbot.irc import IRCConnection, Data


__all__ = ["Frontend"] __all__ = ["Frontend"]
@@ -36,6 +38,7 @@ class Frontend(IRCConnection):
:py:mod:`earwigbot.commands` or the bot's custom command directory :py:mod:`earwigbot.commands` or the bot's custom command directory
(explained in the :doc:`documentation </customizing>`). (explained in the :doc:`documentation </customizing>`).
""" """
NICK_SERVICES = "NickServ"


def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@@ -43,6 +46,8 @@ class Frontend(IRCConnection):
base = super(Frontend, self) base = super(Frontend, self)
base.__init__(cf["host"], cf["port"], cf["nick"], cf["ident"], base.__init__(cf["host"], cf["port"], cf["nick"], cf["ident"],
cf["realname"], bot.logger.getChild("frontend")) cf["realname"], bot.logger.getChild("frontend"))

self._auth_wait = False
self._connect() self._connect()


def __repr__(self): def __repr__(self):
@@ -56,6 +61,11 @@ class Frontend(IRCConnection):
res = "<Frontend {0}!{1} at {2}:{3}>" res = "<Frontend {0}!{1} at {2}:{3}>"
return res.format(self.nick, self.ident, self.host, self.port) return res.format(self.nick, self.ident, self.host, self.port)


def _join_channels(self):
"""Join all startup channels as specified by the config file."""
for chan in self.bot.config.irc["frontend"]["channels"]:
self.join(chan)

def _process_message(self, line): def _process_message(self, line):
"""Process a single message from IRC.""" """Process a single message from IRC."""
if line[1] == "JOIN": if line[1] == "JOIN":
@@ -74,17 +84,27 @@ class Frontend(IRCConnection):
self.bot.commands.call("msg_public", data) self.bot.commands.call("msg_public", data)
self.bot.commands.call("msg", data) self.bot.commands.call("msg", data)


elif line[1] == "NOTICE":
data = Data(self.nick, line, msgtype="NOTICE")
if self._auth_wait and data.nick == self.NICK_SERVICES:
self._auth_wait = False
sleep(2) # Wait for hostname change to propagate
self._join_channels()

elif line[1] == "376": # On successful connection to the server elif line[1] == "376": # On successful connection to the server
# If we're supposed to auth to NickServ, do that: # If we're supposed to auth to NickServ, do that:
try: try:
username = self.bot.config.irc["frontend"]["nickservUsername"] username = self.bot.config.irc["frontend"]["nickservUsername"]
password = self.bot.config.irc["frontend"]["nickservPassword"] password = self.bot.config.irc["frontend"]["nickservPassword"]
except KeyError: except KeyError:
pass
self._join_channels()
else: else:
msg = "IDENTIFY {0} {1}".format(username, password) msg = "IDENTIFY {0} {1}".format(username, password)
self.say("NickServ", msg, hidelog=True)
self.say(self.NICK_SERVICES, msg, hidelog=True)
self._auth_wait = True


# Join all of our startup channels:
for chan in self.bot.config.irc["frontend"]["channels"]:
self.join(chan)
elif line[1] == "401": # No such nickname
if self._auth_wait and line[3] == self.NICK_SERVICES:
# Services is down, or something...?
self._auth_wait = False
self._join_channels()

Loading…
Cancel
Save