2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018, 2020 Sadie Powell <sadie@witchery.services>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "modules/cap.h"
30 class TagMessageDetails;
33 class CTCTags::CapReference : public Cap::Reference
36 CapReference(Module* mod)
37 : Cap::Reference(mod, "message-tags")
42 class CTCTags::TagMessage : public ClientProtocol::Message
45 void PushTarget(const char* target, char status)
49 std::string rawtarget(1, status);
50 rawtarget.append(target);
58 TagMessage(User* source, const Channel* targetchan, const ClientProtocol::TagMap& Tags, char status = 0)
59 : ClientProtocol::Message("TAGMSG", source)
61 PushTarget(targetchan->name.c_str(), status);
65 TagMessage(User* source, const User* targetuser, const ClientProtocol::TagMap& Tags)
66 : ClientProtocol::Message("TAGMSG", source)
68 if (targetuser->registered & REG_NICK)
69 PushParamRef(targetuser->nick);
75 TagMessage(User* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
76 : ClientProtocol::Message("TAGMSG", source)
78 PushTarget(targetstr, status);
82 TagMessage(const char* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
83 : ClientProtocol::Message("TAGMSG", source)
85 PushTarget(targetstr, status);
90 class CTCTags::TagMessageDetails
93 /** Whether to echo the tags at all. */
96 /* Whether to send the original tags back to clients with echo-message support. */
99 /** Whether to update the source user's idle time. */
102 /** The users who are exempted from receiving this message. */
105 /** IRCv3 message tags sent to the server by the user. */
106 const ClientProtocol::TagMap tags_in;
108 /** IRCv3 message tags sent out to users who get this message. */
109 ClientProtocol::TagMap tags_out;
111 TagMessageDetails(const ClientProtocol::TagMap& tags)
113 , echo_original(false)
120 class CTCTags::EventListener
121 : public Events::ModuleEventListener
124 EventListener(Module* mod, unsigned int eventprio = DefaultPriority)
125 : ModuleEventListener(mod, "event/tagmsg", eventprio)
130 /** Called before a user sends a tag message to a channel, a user, or a server glob mask.
131 * @param user The user sending the message.
132 * @param target The target of the message. This can either be a channel, a user, or a server
134 * @param details Details about the message such as the message tags or whether to echo. See the
135 * TagMessageDetails class for more information.
136 * @return MOD_RES_ALLOW to explicitly allow the message, MOD_RES_DENY to explicitly deny the
137 * message, or MOD_RES_PASSTHRU to let another module handle the event.
139 virtual ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, TagMessageDetails& details) { return MOD_RES_PASSTHRU; }
141 /** Called immediately after a user sends a tag message to a channel, a user, or a server glob mask.
142 * @param user The user sending the message.
143 * @param target The target of the message. This can either be a channel, a user, or a server
145 * @param details Details about the message such as the message tags or whether to echo. See the
146 * TagMessageDetails class for more information.
148 virtual void OnUserPostTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
150 /** Called immediately before a user sends a tag message to a channel, a user, or a server glob mask.
151 * @param user The user sending the message.
152 * @param target The target of the message. This can either be a channel, a user, or a server
154 * @param details Details about the message such as the message tags or whether to echo. See the
155 * TagMessageDetails class for more information.
157 virtual void OnUserTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
159 /** Called when a tag message sent by a user to a channel, a user, or a server glob mask is blocked.
160 * @param user The user sending the message.
161 * @param target The target of the message. This can either be a channel, a user, or a server
163 * @param details Details about the message such as the message tags or whether to echo. See the
164 * TagMessageDetails class for more information.
166 virtual void OnUserTagMessageBlocked(User* user, const MessageTarget& target, const TagMessageDetails& details) { }