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),
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()));
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.
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());
}
/**
@FunctionalInterface
public static interface EventProcessor {
- void processEvent(List<String> parameters);
+ void processEvent(Optional<Source> source, List<String> parameters);
}