From 029ac191fbe3b39b323a76790ba1605a380e02e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 14 Apr 2013 11:47:34 +0200 Subject: [PATCH] Rename a bot if its nickname changes. --- .../java/net/pterodactylus/xdcc/core/Core.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index dce8da3..2c68c76 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -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 = 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. * -- 2.7.4