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 const ClientProtocol::TagMap& tags = details.echo_original ? details.tags_in : details.tags_out;
44 if (target.type == MessageTarget::TYPE_USER)
46 User* destuser = target.Get<User>();
47 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type);
48 privmsg.AddTags(tags);
49 localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
51 else if (target.type == MessageTarget::TYPE_CHANNEL)
53 Channel* chan = target.Get<Channel>();
54 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status);
55 privmsg.AddTags(tags);
56 localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
60 const std::string* servername = target.Get<std::string>();
61 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type);
62 privmsg.AddTags(tags);
63 localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
67 void OnUserMessageBlocked(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
69 // Prevent spammers from knowing that their spam was blocked.
70 if (details.echo_original)
71 OnUserPostMessage(user, target, details);
74 Version GetVersion() CXX11_OVERRIDE
76 return Version("Provides the echo-message IRCv3 extension", VF_VENDOR);
80 MODULE_INIT(ModuleIRCv3EchoMessage)