From ad63c79977ba791203fb0f899990ea61878dbf07 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 16 Apr 2013 20:02:08 +0200 Subject: [PATCH] Handle CTCP in notices, too. --- .../java/net/pterodactylus/irc/Connection.java | 12 ++++ .../irc/event/ChannelNoticeReceived.java | 71 +++++++++++++++++++++ .../pterodactylus/irc/event/NoticeReceived.java | 72 ---------------------- .../irc/event/PrivateNoticeReceived.java | 72 ++++++++++++++++++++++ 4 files changed, 155 insertions(+), 72 deletions(-) create mode 100644 src/main/java/net/pterodactylus/irc/event/ChannelNoticeReceived.java delete mode 100644 src/main/java/net/pterodactylus/irc/event/NoticeReceived.java create mode 100644 src/main/java/net/pterodactylus/irc/event/PrivateNoticeReceived.java diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index bf6065f..530b0c7 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -44,6 +44,7 @@ import net.pterodactylus.irc.event.ChannelMessageReceived; import net.pterodactylus.irc.event.ChannelNicknames; import net.pterodactylus.irc.event.ChannelNotJoined; import net.pterodactylus.irc.event.ChannelNotJoined.Reason; +import net.pterodactylus.irc.event.ChannelNoticeReceived; import net.pterodactylus.irc.event.ChannelTopic; import net.pterodactylus.irc.event.ClientQuit; import net.pterodactylus.irc.event.ConnectionClosed; @@ -56,6 +57,7 @@ import net.pterodactylus.irc.event.NicknameChanged; import net.pterodactylus.irc.event.NicknameInUseReceived; import net.pterodactylus.irc.event.NoNicknameGivenReceived; import net.pterodactylus.irc.event.PrivateMessageReceived; +import net.pterodactylus.irc.event.PrivateNoticeReceived; import net.pterodactylus.irc.event.UnknownReplyReceived; import net.pterodactylus.irc.util.RandomNickname; @@ -339,6 +341,16 @@ public class Connection extends AbstractExecutionThreadService implements Servic eventBus.post(new ChannelMessageReceived(this, recipient, reply.source().get(), message)); } + } else if (command.equalsIgnoreCase("NOTICE")) { + String recipient = parameters.get(0); + String message = parameters.get(1); + if (message.startsWith("\u0001") && message.endsWith("\u0001")) { + /* CTCP! */ + handleCtcp(reply.source().get(), message); + } else if (!channelTypes.contains(recipient.charAt(0))) { + eventBus.post(new PrivateNoticeReceived(this, reply)); + } else { + eventBus.post(new ChannelNoticeReceived(this, reply.source().get(), recipient, message)); } /* 43x replies are for nick change errors. */ diff --git a/src/main/java/net/pterodactylus/irc/event/ChannelNoticeReceived.java b/src/main/java/net/pterodactylus/irc/event/ChannelNoticeReceived.java new file mode 100644 index 0000000..286c61a --- /dev/null +++ b/src/main/java/net/pterodactylus/irc/event/ChannelNoticeReceived.java @@ -0,0 +1,71 @@ +/* + * XdccDownloader - ChannelNoticeReceived.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.irc.event; + +import net.pterodactylus.irc.Connection; +import net.pterodactylus.irc.Source; + +/** + * Notifies a listener that a notice was received on a channel. + * + * @author David ‘Bombe’ Roden + */ +public class ChannelNoticeReceived extends AbstractChannelEvent { + + private final Source client; + + /** The text of the notice. */ + private final String text; + + /** + * Creates a new notice received event. + * + * @param connection + * The connection the event occured on + * @param reply + * The reply that caused the event + */ + public ChannelNoticeReceived(Connection connection, Source client, String channel, String text) { + super(connection, channel); + this.client = client; + this.text = text; + } + + // + // ACCESSORS + // + + /** + * Returns the target of the notice. + * + * @return The target of the notice + */ + public Source client() { + return client; + } + + /** + * Returns the text of the notice. + * + * @return The text of the notice + */ + public String text() { + return text; + } + +} diff --git a/src/main/java/net/pterodactylus/irc/event/NoticeReceived.java b/src/main/java/net/pterodactylus/irc/event/NoticeReceived.java deleted file mode 100644 index f4b34c8..0000000 --- a/src/main/java/net/pterodactylus/irc/event/NoticeReceived.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * XdccDownloader - NoticeReceived.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.irc.event; - -import net.pterodactylus.irc.Connection; -import net.pterodactylus.irc.Reply; - -/** - * Notifies a listener that a notice was received. - * - * @author David ‘Bombe’ Roden - */ -public class NoticeReceived extends AbstractReplyEvent { - - /** The target of the notice. */ - private final String target; - - /** The text of the notice. */ - private final String text; - - /** - * Creates a new notice received event. - * - * @param connection - * The connection the event occured on - * @param reply - * The reply that caused the event - */ - public NoticeReceived(Connection connection, Reply reply) { - super(connection, reply); - this.target = reply.parameters().get(0); - this.text = reply.parameters().get(1); - } - - // - // ACCESSORS - // - - /** - * Returns the target of the notice. - * - * @return The target of the notice - */ - public String target() { - return target; - } - - /** - * Returns the text of the notice. - * - * @return The text of the notice - */ - public String text() { - return text; - } - -} diff --git a/src/main/java/net/pterodactylus/irc/event/PrivateNoticeReceived.java b/src/main/java/net/pterodactylus/irc/event/PrivateNoticeReceived.java new file mode 100644 index 0000000..afb6acc --- /dev/null +++ b/src/main/java/net/pterodactylus/irc/event/PrivateNoticeReceived.java @@ -0,0 +1,72 @@ +/* + * XdccDownloader - PrivateNoticeReceived.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.irc.event; + +import net.pterodactylus.irc.Connection; +import net.pterodactylus.irc.Reply; + +/** + * Notifies a listener that a notice was received. + * + * @author David ‘Bombe’ Roden + */ +public class PrivateNoticeReceived extends AbstractReplyEvent { + + /** The target of the notice. */ + private final String target; + + /** The text of the notice. */ + private final String text; + + /** + * Creates a new notice received event. + * + * @param connection + * The connection the event occured on + * @param reply + * The reply that caused the event + */ + public PrivateNoticeReceived(Connection connection, Reply reply) { + super(connection, reply); + this.target = reply.parameters().get(0); + this.text = reply.parameters().get(1); + } + + // + // ACCESSORS + // + + /** + * Returns the target of the notice. + * + * @return The target of the notice + */ + public String target() { + return target; + } + + /** + * Returns the text of the notice. + * + * @return The text of the notice + */ + public String text() { + return text; + } + +} -- 2.7.4