🚸 Try to activate a bot’s active mode before requesting a pack
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / core / Core.java
index 8ef074c..ea335ee 100644 (file)
@@ -39,6 +39,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
@@ -319,6 +320,7 @@ public class Core extends AbstractExecutionThreadService {
                downloads.put(pack.name(), download);
 
                try {
+                       connection.sendMessage(bot.name(), "XDCC OPTION +ACTIVE");
                        connection.sendMessage(bot.name(), "XDCC SEND " + pack.id());
                } catch (IOException ioe1) {
                        logger.warn("Could not send message to bot!", ioe1);
@@ -891,34 +893,29 @@ public class Core extends AbstractExecutionThreadService {
                if (!network.isPresent()) {
                        return;
                }
-               eventBus.post(new GenericMessage("a"));
 
                Set<Download> openDownloads = downloads.values().stream()
                                .filter(download -> download.bot().name().equalsIgnoreCase(dccSendReceived.source().nick().orNull()))
                                .filter(download -> download.dccReceiver() == null)
                                .collect(toSet());
-               eventBus.post(new GenericMessage("b"));
 
                if (openDownloads.isEmpty()) {
                        /* I don't think we requested this. */
                        eventBus.post(new GenericMessage(format("Ignoring offer for %s, no open download from %s.", dccSendReceived.filename(), dccSendReceived.source())));
                        return;
                }
-               eventBus.post(new GenericMessage("c"));
 
                /* check if it’s already downloading. */
-               if (downloads.values().stream().anyMatch(download -> download.filename().equals(dccSendReceived.filename()) && download.dccReceiver() != null)) {
+               if (downloads.values().stream().anyMatch(download -> Objects.equals(download.filename(), dccSendReceived.filename()) && download.dccReceiver() != null)) {
                        eventBus.post(new GenericMessage(format("Ignoring offer for %s, it’s already being downloaded.", dccSendReceived.filename())));
                        return;
                }
-               eventBus.post(new GenericMessage("d"));
 
                Download download = openDownloads.stream()
-                               .filter(it -> it.filename().equals(dccSendReceived.filename()))
+                               .filter(it -> Objects.equals(it.filename(), dccSendReceived.filename()))
                                .findFirst()
                                .orElse(openDownloads.iterator().next());
-               eventBus.post(new GenericMessage("e"));
-               eventBus.post(new GenericMessage(format("Downloading %s from %s as %s.", dccSendReceived.filename(), dccSendReceived.source(), download.filename())));
+               eventBus.post(new GenericMessage(format("Downloading %s from %s as %s.", dccSendReceived.filename(), dccSendReceived.source(), download.pack().name())));
 
                /* check if the file already exists. */
                File outputFile = new File(temporaryDirectory, dccSendReceived.filename());