diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-12-06 11:30:13 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-12-06 11:30:13 +0100 |
commit | f9f59c2706f965f7f753271f54536cf0531a2ba8 (patch) | |
tree | e3c90bc5a3d54021ad95a72b2685d7d2f6f211f5 /src/modules | |
parent | fd87f9f073dff6e2f21a92c96144fb6c0a46e8e3 (diff) |
Add m_ircv3_invitenotify which implements the IRCv3.2 invite-notify extension
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_ircv3_invitenotify.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/modules/m_ircv3_invitenotify.cpp b/src/modules/m_ircv3_invitenotify.cpp new file mode 100644 index 000000000..3783ff33c --- /dev/null +++ b/src/modules/m_ircv3_invitenotify.cpp @@ -0,0 +1,68 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com> + * + * This file is part of InspIRCd. InspIRCd 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, version 2. + * + * 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 <http://www.gnu.org/licenses/>. + */ + + +#include "inspircd.h" +#include "modules/cap.h" + +class ModuleIRCv3InviteNotify : public Module +{ + Cap::Capability cap; + + public: + ModuleIRCv3InviteNotify() + : cap(this, "invite-notify") + { + } + + void OnUserInvite(User* source, User* dest, Channel* chan, time_t expiry, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE + { + std::string msg = "INVITE "; + msg.append(dest->nick).append(1, ' ').append(chan->name); + const Channel::MemberMap& users = chan->GetUsers(); + for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i) + { + User* user = i->first; + // Skip members who don't use this extension or were excluded by other modules + if ((!cap.get(user)) || (notifyexcepts.count(user))) + continue; + + Membership* memb = i->second; + // Check whether the member has a high enough rank to see the notification + if (memb->getRank() < notifyrank) + continue; + + // Send and add the user to the exceptions so they won't get the NOTICE invite announcement message + user->WriteFrom(source, msg); + notifyexcepts.insert(user); + } + } + + void Prioritize() CXX11_OVERRIDE + { + // Prioritize after all modules to see all excepted users + ServerInstance->Modules.SetPriority(this, I_OnUserInvite, PRIORITY_LAST); + } + + Version GetVersion() CXX11_OVERRIDE + { + return Version("Provides the invite-notify IRCv3.2 extension", VF_VENDOR); + } +}; + +MODULE_INIT(ModuleIRCv3InviteNotify) |