2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2013-2015 Peter Powell <petpow@saberuk.com>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modules/cap.h"
24 class ModuleIRCv3EchoMessage : public Module
29 ModuleIRCv3EchoMessage()
30 : cap(this, "echo-message")
34 void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
36 if (!cap.get(user) || !details.echo)
39 // Caps are only set on local users
40 LocalUser* const localuser = static_cast<LocalUser*>(user);
42 const std::string& text = details.echo_original ? details.original_text : details.text;
43 if (target.type == MessageTarget::TYPE_USER)
45 User* destuser = target.Get<User>();
46 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type);
47 privmsg.AddTags(details.tags_in);
48 localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
50 else if (target.type == MessageTarget::TYPE_CHANNEL)
52 Channel* chan = target.Get<Channel>();
53 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status);
54 privmsg.AddTags(details.tags_in);
55 localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
59 const std::string* servername = target.Get<std::string>();
60 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type);
61 privmsg.AddTags(details.tags_in);
62 localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
66 void OnUserMessageBlocked(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
68 // Prevent spammers from knowing that their spam was blocked.
69 if (details.echo_original)
70 OnUserPostMessage(user, target, details);
73 Version GetVersion() CXX11_OVERRIDE
75 return Version("Provides the echo-message IRCv3 extension", VF_VENDOR);
79 MODULE_INIT(ModuleIRCv3EchoMessage)