]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_ircv3_invitenotify.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / modules / m_ircv3_invitenotify.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2015, 2018 Attila Molnar <attilamolnar@hush.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 class ModuleIRCv3InviteNotify : public Module
25 {
26         Cap::Capability cap;
27
28  public:
29         ModuleIRCv3InviteNotify()
30                 : cap(this, "invite-notify")
31         {
32         }
33
34         void OnUserInvite(User* source, User* dest, Channel* chan, time_t expiry, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE
35         {
36                 ClientProtocol::Messages::Invite invitemsg(source, dest, chan);
37                 ClientProtocol::Event inviteevent(ServerInstance->GetRFCEvents().invite, invitemsg);
38                 const Channel::MemberMap& users = chan->GetUsers();
39                 for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
40                 {
41                         User* user = i->first;
42                         // Skip members who don't use this extension or were excluded by other modules
43                         if ((!cap.get(user)) || (notifyexcepts.count(user)))
44                                 continue;
45
46                         Membership* memb = i->second;
47                         // Check whether the member has a high enough rank to see the notification
48                         if (memb->getRank() < notifyrank)
49                                 continue;
50
51                         // Caps are only set on local users
52                         LocalUser* const localuser = static_cast<LocalUser*>(user);
53                         // Send and add the user to the exceptions so they won't get the NOTICE invite announcement message
54                         localuser->Send(inviteevent);
55                         notifyexcepts.insert(user);
56                 }
57         }
58
59         void Prioritize() CXX11_OVERRIDE
60         {
61                 // Prioritize after all modules to see all excepted users
62                 ServerInstance->Modules.SetPriority(this, I_OnUserInvite, PRIORITY_LAST);
63         }
64
65         Version GetVersion() CXX11_OVERRIDE
66         {
67                 return Version("Provides the IRCv3 invite-notify client capability.", VF_VENDOR);
68         }
69 };
70
71 MODULE_INIT(ModuleIRCv3InviteNotify)