From 1e02d0f9e13fd48ea52c630dce2f27dd4cf8577f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 15 Oct 2014 21:40:41 +0200 Subject: [PATCH] Check if we have been kicked and send message if so. --- .../java/net/pterodactylus/xdcc/core/Core.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index eb0036c..1822ee6 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -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 = 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("") + ))); + } + } + + 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. * -- 2.7.4