Commits

Anonymous committed 255387a

Made irclib.py and ircbot.py better at handling nickname changes
in the connection handshake phase.

Comments (0)

Files changed (4)

+2003-10-29  Joel Rosdahl  <joel@rosdahl.net>
+
+	* irclib.py (ServerConnection.process_data): Record nickname when
+	welcome message is sent to trap nickname change triggered in a
+	nicknameinuse callback.
+
+	* ircbot.py (SingleServerIRCBot._on_join): Use
+	Connection.get_nickname instead of relying on self._nickname.
+	(SingleServerIRCBot._on_kick): Likewise.
+	(SingleServerIRCBot._on_part): And here too.
+	(SingleServerIRCBot._on_nick): No need to remember nickname change
+	here.
+
 2003-08-31  Joel Rosdahl  <joel@rosdahl.net>
 
 	* Released version 0.4.0.
         """[Internal]"""
         ch = e.target()
         nick = nm_to_n(e.source())
-        if nick == self._nickname:
+        if nick == c.get_nickname():
             self.channels[ch] = Channel()
         self.channels[ch].add_user(nick)
 
         nick = e.arguments()[0]
         channel = e.target()
 
-        if nick == self._nickname:
+        if nick == c.get_nickname():
             del self.channels[channel]
         else:
             self.channels[channel].remove_user(nick)
         for ch in self.channels.values():
             if ch.has_user(before):
                 ch.change_nick(before, after)
-        if nm_to_n(before) == self._nickname:
-            self._nickname = after
 
     def _on_part(self, c, e):
         """[Internal]"""
         nick = nm_to_n(e.source())
         channel = e.target()
 
-        if nick == self._nickname:
+        if nick == c.get_nickname():
             del self.channels[channel]
         else:
             self.channels[channel].remove_user(nick)
             if command == "nick":
                 if nm_to_n(prefix) == self.real_nickname:
                     self.real_nickname = arguments[0]
+            elif command == "001":
+                # Record the nickname in case the client changed nick
+                # in a nicknameinuse callback.
+                self.real_nickname = arguments[0]
 
             if command in ["privmsg", "notice"]:
                 target, message = arguments[0], arguments[1]
         self.channel = channel
         self.start()
 
+    def on_nicknameinuse(self, c, e):
+        c.nick(c.get_nickname() + "_")
+
     def on_welcome(self, c, e):
         c.join(self.channel)