From: David ‘Bombe’ Roden Date: Wed, 22 Oct 2014 19:41:48 +0000 (+0200) Subject: Move nick changes into simple command handler. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1aa7f843043b8723a02b4bbd88eb21ae8b7db881;p=xudocci.git Move nick changes into simple command handler. --- diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index d12cc77..30344be 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -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())); diff --git a/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java b/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java index 24df16f..3f75d0e 100644 --- a/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java +++ b/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java @@ -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 parameters); + void processEvent(Optional source, List parameters); }