From: David ‘Bombe’ Roden Date: Thu, 11 Apr 2013 20:49:39 +0000 (+0200) Subject: Remove a bot when it quits. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f1762992ce7d64ad321cf95c92796577d0819b80;p=xudocci.git Remove a bot when it quits. --- diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index 15c8ff5..5b460da 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -45,6 +45,7 @@ import net.pterodactylus.irc.event.ChannelNicknames; import net.pterodactylus.irc.event.ChannelNotJoined; import net.pterodactylus.irc.event.ChannelNotJoined.Reason; import net.pterodactylus.irc.event.ChannelTopic; +import net.pterodactylus.irc.event.ClientQuit; import net.pterodactylus.irc.event.ConnectionEstablished; import net.pterodactylus.irc.event.ConnectionFailed; import net.pterodactylus.irc.event.DccSendReceived; @@ -391,6 +392,8 @@ public class Connection extends AbstractExecutionThreadService implements Servic nicks.clear(); } else if (command.equalsIgnoreCase("PART")) { eventBus.post(new ChannelLeft(this, parameters.get(0), reply.source().get(), parameters.get(1))); + } else if (command.equalsIgnoreCase("QUIT")) { + eventBus.post(new ClientQuit(this, reply.source().get(), parameters.get(0))); /* common channel join errors. */ } else if (command.equals("474")) { diff --git a/src/main/java/net/pterodactylus/irc/event/ClientQuit.java b/src/main/java/net/pterodactylus/irc/event/ClientQuit.java new file mode 100644 index 0000000..d7f7aff --- /dev/null +++ b/src/main/java/net/pterodactylus/irc/event/ClientQuit.java @@ -0,0 +1,74 @@ +/* + * XdccDownloader - ClientQuit.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.irc.event; + +import net.pterodactylus.irc.Connection; +import net.pterodactylus.irc.Source; + +/** + * Notifies a listener that a client has quit. + * + * @author David ‘Bombe’ Roden + */ +public class ClientQuit extends AbstractConnectionEvent { + + /** The client that quit. */ + private final Source client; + + /** The message given by the client. */ + private final String message; + + /** + * Creates a new client quit event. + * + * @param connection + * The connection on which the event occured + * @param client + * The client that quit + * @param message + * The message given by the client + */ + public ClientQuit(Connection connection, Source client, String message) { + super(connection); + this.client = client; + this.message = message; + } + + // + // ACCESSORS + // + + /** + * Returns the client that quit. + * + * @return The client that quit + */ + public Source client() { + return client; + } + + /** + * Returns the message given by the client. + * + * @return The message given by the client + */ + public String message() { + return message; + } + +} diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index 4d1e1ac..64fdbec 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -36,6 +36,7 @@ import net.pterodactylus.irc.DccReceiver; import net.pterodactylus.irc.event.ChannelJoined; import net.pterodactylus.irc.event.ChannelLeft; import net.pterodactylus.irc.event.ChannelMessageReceived; +import net.pterodactylus.irc.event.ClientQuit; import net.pterodactylus.irc.event.ConnectionEstablished; import net.pterodactylus.irc.event.DccDownloadFailed; import net.pterodactylus.irc.event.DccDownloadFinished; @@ -344,6 +345,22 @@ public class Core extends AbstractIdleService { } /** + * Removes a client (which may be a bot) from the table of known bots. + * + * @param clientQuit + * The client quit event + */ + @Subscribe + public void clientQuit(ClientQuit clientQuit) { + Optional network = getNetwork(clientQuit.connection()); + if (!network.isPresent()) { + return; + } + + networkBots.remove(network.get(), clientQuit.client().nick().get()); + } + + /** * If a message on a channel is received, it is parsed for pack information * with is then added to a bot. *