Rename a bot if its nickname changes.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Apr 2013 09:47:34 +0000 (11:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Apr 2013 09:47:34 +0000 (11:47 +0200)
src/main/java/net/pterodactylus/xdcc/core/Core.java

index dce8da3..2c68c76 100644 (file)
@@ -42,6 +42,7 @@ import net.pterodactylus.irc.event.DccAcceptReceived;
 import net.pterodactylus.irc.event.DccDownloadFailed;
 import net.pterodactylus.irc.event.DccDownloadFinished;
 import net.pterodactylus.irc.event.DccSendReceived;
+import net.pterodactylus.irc.event.NicknameChanged;
 import net.pterodactylus.irc.event.PrivateMessageReceived;
 import net.pterodactylus.irc.util.MessageCleaner;
 import net.pterodactylus.irc.util.RandomNickname;
@@ -369,6 +370,28 @@ public class Core extends AbstractIdleService {
        }
 
        /**
+        * If the nickname of a bit changes, remove it from the old name and store it
+        * under the new name.
+        *
+        * @param nicknameChanged
+        *              The nickname changed event
+        */
+       @Subscribe
+       public void nicknameChanged(NicknameChanged nicknameChanged) {
+               Optional<Network> network = getNetwork(nicknameChanged.connection());
+               if (!network.isPresent()) {
+                       return;
+               }
+
+               Bot bot = networkBots.remove(network.get(), nicknameChanged.client().nick().get());
+               if (bot == null) {
+                       return;
+               }
+
+               networkBots.put(network.get(), nicknameChanged.newNickname(), bot);
+       }
+
+       /**
         * If a message on a channel is received, it is parsed for pack information
         * with is then added to a bot.
         *