1 package net.pterodactylus.irc.connection;
3 import static java.util.Arrays.asList;
5 import java.util.ArrayList;
8 import net.pterodactylus.irc.Connection;
9 import net.pterodactylus.irc.Nickname;
10 import net.pterodactylus.irc.Reply;
11 import net.pterodactylus.irc.event.ChannelNicknames;
13 import com.google.common.eventbus.EventBus;
16 * Handles the list of nicknames that are sent on a {@code JOIN}.
18 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
20 public class ChannelNickHandler implements Handler {
22 private static final List<String> COMMANDS_TO_HANDLE =
24 private final EventBus eventBus;
25 private final Connection connection;
26 private final PrefixHandler prefixHandler;
27 private final List<Nickname> nicknames = new ArrayList<>();
29 public ChannelNickHandler(EventBus eventBus, Connection connection,
30 PrefixHandler prefixHandler) {
31 this.eventBus = eventBus;
32 this.connection = connection;
33 this.prefixHandler = prefixHandler;
37 public boolean willHandle(Reply reply) {
38 return COMMANDS_TO_HANDLE.contains(reply.command());
42 public void handleReply(Reply reply) {
43 String command = reply.command();
44 List<String> parameters = reply.parameters();
45 if (command.equals("353")) {
46 asList(parameters.get(3).split(" ")).stream().forEach(
47 (nick) -> nicknames.add(prefixHandler.getNickname(nick)));
48 } else if (command.equals("366")) {
49 eventBus.post(new ChannelNicknames(connection, parameters.get(1),