]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_ircv3_echomessage.cpp
056b02194cb46f30e45a894d27f35b9a1e55ae75
[user/henk/code/inspircd.git] / src / modules / m_ircv3_echomessage.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
5  *   Copyright (C) 2013-2015 Peter Powell <petpow@saberuk.com>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "modules/cap.h"
23
24 static const char* MessageTypeStringSp[] = { "PRIVMSG ", "NOTICE " };
25
26 class ModuleIRCv3EchoMessage : public Module
27 {
28         Cap::Capability cap;
29
30  public:
31         ModuleIRCv3EchoMessage()
32                 : cap(this, "echo-message")
33         {
34         }
35
36         void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
37         {
38                 if (!cap.get(user))
39                         return;
40
41                 std::string msg = MessageTypeStringSp[details.type];
42                 if (target.type == MessageTarget::TYPE_USER)
43                 {
44                         User* destuser = target.Get<User>();
45                         msg.append(destuser->nick);
46                 }
47                 else if (target.type == MessageTarget::TYPE_CHANNEL)
48                 {
49                         if (target.status)
50                                 msg.push_back(target.status);
51
52                         Channel* chan = target.Get<Channel>();
53                         msg.append(chan->name);
54                 }
55                 else
56                 {
57                         const std::string* servername = target.Get<std::string>();
58                         msg.append(*servername);
59                 }
60                 msg.append(" :").append(details.echooriginal ? details.originaltext : details.text);
61                 user->WriteFrom(user, msg);
62         }
63
64         void OnUserMessageBlocked(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
65         {
66                 // Prevent spammers from knowing that their spam was blocked.
67                 if (details.echooriginal)
68                         OnUserPostMessage(user, target, details);
69         }
70
71         Version GetVersion() CXX11_OVERRIDE
72         {
73                 return Version("Provides the echo-message IRCv3.2 extension", VF_VENDOR);
74         }
75 };
76
77 MODULE_INIT(ModuleIRCv3EchoMessage)