import net.pterodactylus.irc.ConnectionBuilder;
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.ConnectionEstablished;
import net.pterodactylus.irc.event.DccDownloadFailed;
import net.pterodactylus.xdcc.core.event.DownloadFailed;
import net.pterodactylus.xdcc.core.event.DownloadFinished;
import net.pterodactylus.xdcc.core.event.DownloadStarted;
+import net.pterodactylus.xdcc.core.event.GenericMessage;
import net.pterodactylus.xdcc.core.event.MessageReceived;
import net.pterodactylus.xdcc.data.Bot;
import net.pterodactylus.xdcc.data.Channel;
}
/**
+ * Removes bots that leave a channel, or channels when it’s us that’s leaving.
+ *
+ * @param channelLeft
+ * The channel left event
+ */
+ @Subscribe
+ public void channelLeft(ChannelLeft channelLeft) {
+ Optional<Network> network = getNetwork(channelLeft.connection());
+ if (!network.isPresent()) {
+ return;
+ }
+
+ Bot bot = networkBots.get(network.get(), channelLeft.client().nick().get());
+ if (bot == null) {
+ /* maybe it was us? */
+ if (channelLeft.connection().isSource(channelLeft.client())) {
+ Optional<Channel> channel = getChannel(network.get(), channelLeft.channel());
+ if (!channel.isPresent()) {
+ /* maybe it was an extra channel? */
+ channel = getExtraChannel(network.get(), channelLeft.channel());
+ if (!channel.isPresent()) {
+ /* okay, whatever. */
+ return;
+ }
+
+ extraChannels.remove(channel);
+ } else {
+ channels.remove(channel.get());
+ }
+
+ eventBus.post(new GenericMessage(String.format("Left Channel %s on %s.", channel.get().name(), channel.get().network().name())));
+ }
+
+ return;
+ }
+
+ networkBots.remove(network.get(), channelLeft.client().nick().get());
+ }
+
+ /**
* If a message on a channel is received, it is parsed for pack information
* with is then added to a bot.
*
}
/**
+ * Returns the extra channel for the given network and name.
+ *
+ * @param network
+ * The network the channel is located on
+ * @param channelName
+ * The name of the channel
+ * @return The extra channel, or {@link Optional#absent()} if no extra channel
+ * matching the given network and name was found
+ */
+ public Optional<Channel> getExtraChannel(Network network, String channelName) {
+ for (Channel channel : extraChannels) {
+ if (channel.network().equals(network) && (channel.name().equalsIgnoreCase(channelName))) {
+ return Optional.of(channel);
+ }
+ }
+ return Optional.absent();
+ }
+
+ /**
* Parses {@link Pack} information from the given message.
*
* @param message
--- /dev/null
+/*
+ * XdccDownloader - Information.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.xdcc.core.event;
+
+/**
+ * Generic message for all consoles.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class GenericMessage {
+
+ /** The message. */
+ private final String message;
+
+ /**
+ * Creates a new generic message event.
+ *
+ * @param message
+ * The message
+ */
+ public GenericMessage(String message) {
+ this.message = message;
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the message.
+ *
+ * @return The message
+ */
+ public String message() {
+ return message;
+ }
+
+}