1 package net.pterodactylus.irc.connection;
3 import static java.util.Arrays.asList;
7 import net.pterodactylus.irc.Connection;
8 import net.pterodactylus.irc.Reply;
9 import net.pterodactylus.irc.event.MotdReceived;
11 import com.google.common.eventbus.EventBus;
14 * Handles the MOTD sent by the server.
16 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
19 public class MotdHandler implements Handler {
21 private static final List<String> COMMANDS = asList("372", "375", "376");
22 private final EventBus eventBus;
23 private final Connection connection;
24 private final StringBuilder motd = new StringBuilder();
26 public MotdHandler(EventBus eventBus, Connection connection) {
27 this.eventBus = eventBus;
28 this.connection = connection;
32 public boolean willHandle(Reply reply) {
33 return COMMANDS.contains(reply.command());
37 public void handleReply(Reply reply) {
38 String command = reply.command();
39 List<String> parameters = reply.parameters();
41 /* 375, 372, and 376 handle the server’s MOTD. */
42 if (command.equals("375")) {
44 motd.append(parameters.get(1)).append('\n');
45 } else if (command.equals("372")) {
46 motd.append(parameters.get(1)).append('\n');
47 } else if (command.equals("376")) {
48 motd.append(parameters.get(1)).append('\n');
49 eventBus.post(new MotdReceived(connection, motd.toString()));