Move nick changes into simple command handler.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 22 Oct 2014 19:41:48 +0000 (21:41 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 22 Oct 2014 19:42:26 +0000 (21:42 +0200)
src/main/java/net/pterodactylus/irc/Connection.java
src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java

index d12cc77..30344be 100644 (file)
@@ -370,8 +370,11 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                        new CtcpHandler(eventBus, this),
                                        new ChannelNickHandler(eventBus, this, prefixHandler),
                                        new SimpleCommandHandler()
-                                                       .addCommand("431", (parameters) -> eventBus.post(
-                                                                       new NoNicknameGivenReceived(this))),
+                                                       .addCommand("431", (s, p) -> eventBus.post(
+                                                                       new NoNicknameGivenReceived(this)))
+                                                       .addCommand("NICK", (s, p) -> eventBus.post(
+                                                                       new NicknameChanged(this, s.get(),
+                                                                                       p.get(0)))),
                                        new MotdHandler(eventBus, this),
                                        new ChannelNotJoinedHandler(eventBus, this),
                                        new ConnectionEstablishHandler(eventBus, this),
@@ -401,10 +404,6 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                                eventBus.post(new NicknameInUseReceived(this, reply));
                                        }
 
-                               /* client stuff. */
-                               } else if (command.equalsIgnoreCase("NICK")) {
-                                       eventBus.post(new NicknameChanged(this, reply.source().get(), parameters.get(0)));
-
                                /* channel stuff. */
                                } else if (command.equalsIgnoreCase("JOIN")) {
                                        eventBus.post(new ChannelJoined(this, parameters.get(0), reply.source().get()));
index 24df16f..3f75d0e 100644 (file)
@@ -5,6 +5,9 @@ import java.util.List;
 import java.util.Map;
 
 import net.pterodactylus.irc.Reply;
+import net.pterodactylus.irc.Source;
+
+import com.google.common.base.Optional;
 
 /**
  * Handler that can process any number of events.
@@ -18,20 +21,20 @@ public class SimpleCommandHandler implements Handler {
 
        public SimpleCommandHandler addCommand(String command,
                        EventProcessor eventProcessor) {
-               commandEventSenders.put(command, eventProcessor);
+               commandEventSenders.put(command.toLowerCase(), eventProcessor);
                return this;
        }
 
        @Override
        public boolean willHandle(Reply reply) {
-               return commandEventSenders.containsKey(reply.command());
+               return commandEventSenders.containsKey(reply.command().toLowerCase());
        }
 
        @Override
        public void handleReply(Reply reply) {
                EventProcessor eventProcessor =
-                               commandEventSenders.get(reply.command());
-               eventProcessor.processEvent(reply.parameters());
+                               commandEventSenders.get(reply.command().toLowerCase());
+               eventProcessor.processEvent(reply.source(), reply.parameters());
        }
 
        /**
@@ -42,7 +45,7 @@ public class SimpleCommandHandler implements Handler {
        @FunctionalInterface
        public static interface EventProcessor {
 
-               void processEvent(List<String> parameters);
+               void processEvent(Optional<Source> source, List<String> parameters);
 
        }