Check if we have been kicked and send message if so.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Oct 2014 19:40:41 +0000 (21:40 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Oct 2014 19:40:41 +0000 (21:40 +0200)
src/main/java/net/pterodactylus/xdcc/core/Core.java

index eb0036c..1822ee6 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.xdcc.core;
 
+import static java.lang.String.format;
 import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance;
 import static net.pterodactylus.xdcc.data.Channel.TO_NETWORK;
 import static net.pterodactylus.xdcc.data.Download.FILTER_RUNNING;
@@ -48,6 +49,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.KickedFromChannel;
 import net.pterodactylus.irc.event.NicknameChanged;
 import net.pterodactylus.irc.event.PrivateMessageReceived;
 import net.pterodactylus.irc.event.PrivateNoticeReceived;
@@ -575,6 +577,28 @@ public class Core extends AbstractExecutionThreadService {
                networkBots.remove(network.get(), channelLeft.client().nick().get());
        }
 
+       @Subscribe
+       public void kickedFromChannel(KickedFromChannel kickedFromChannel) {
+               Optional<Network> network = getNetwork(kickedFromChannel.connection());
+               if (!network.isPresent()) {
+                       return;
+               }
+
+               /* have we been kicked? */
+               if (nicknameMatchesConnection(kickedFromChannel.connection(), kickedFromChannel.kickee())) {
+                       eventBus.post(new GenericMessage(format(
+                                       "Kicked from %s/%s by %s: %s",
+                                       kickedFromChannel.channel(), network.get(),
+                                       kickedFromChannel.kicker(),
+                                       kickedFromChannel.reason().or("<unknown>")
+                       )));
+               }
+       }
+
+       private boolean nicknameMatchesConnection(Connection connection, String nickname) {
+               return connection.nickname().equalsIgnoreCase(nickname);
+       }
+
        /**
         * Removes a client (which may be a bot) from the table of known bots.
         *