Remove downloads when they have finished, too.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / core / Core.java
index df6d278..7a35624 100644 (file)
@@ -39,6 +39,7 @@ import net.pterodactylus.irc.event.ConnectionEstablished;
 import net.pterodactylus.irc.event.DccDownloadFailed;
 import net.pterodactylus.irc.event.DccDownloadFinished;
 import net.pterodactylus.irc.event.DccSendReceived;
+import net.pterodactylus.irc.event.PrivateMessageReceived;
 import net.pterodactylus.irc.util.MessageCleaner;
 import net.pterodactylus.irc.util.RandomNickname;
 import net.pterodactylus.xdcc.core.event.BotAdded;
@@ -46,6 +47,7 @@ import net.pterodactylus.xdcc.core.event.CoreStarted;
 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.MessageReceived;
 import net.pterodactylus.xdcc.data.Bot;
 import net.pterodactylus.xdcc.data.Channel;
 import net.pterodactylus.xdcc.data.Download;
@@ -343,6 +345,17 @@ public class Core extends AbstractIdleService {
        }
 
        /**
+        * Forward all private messages to every console.
+        *
+        * @param privateMessageReceived
+        *              The private message recevied event
+        */
+       @Subscribe
+       public void privateMessageReceived(PrivateMessageReceived privateMessageReceived) {
+               eventBus.post(new MessageReceived(privateMessageReceived.source(), privateMessageReceived.message()));
+       }
+
+       /**
         * Starts a DCC download.
         *
         * @param dccSendReceived
@@ -395,6 +408,8 @@ public class Core extends AbstractIdleService {
                        File file = new File(download.filename());
                        file.renameTo(new File(finalDirectory, download.pack().name()));
                        eventBus.post(new DownloadFinished(download));
+                       dccReceivers.remove(dccDownloadFinished.dccReceiver());
+                       downloads.remove(download);
                } catch (IOException ioe1) {
                        /* TODO - handle all the errors. */
                        logger.log(Level.WARNING, String.format("Could not move file %s to directory %s.", download.filename(), finalDirectory), ioe1);
@@ -418,6 +433,8 @@ public class Core extends AbstractIdleService {
                try {
                        Closeables.close(download.outputStream(), true);
                        eventBus.post(new DownloadFailed(download));
+                       dccReceivers.remove(dccDownloadFailed.dccReceiver());
+                       downloads.remove(download);
                } catch (IOException ioe1) {
                        /* swallow silently. */
                }
@@ -457,7 +474,7 @@ public class Core extends AbstractIdleService {
         */
        public Optional<Channel> getChannel(Network network, String channelName) {
                for (Channel channel : channels) {
-                       if (channel.network().equals(network) && (channel.name().equals(channelName))) {
+                       if (channel.network().equals(network) && (channel.name().equalsIgnoreCase(channelName))) {
                                return Optional.of(channel);
                        }
                }