]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/ctctags.h
Remove the Kiwi links from the readme.
[user/henk/code/inspircd.git] / include / modules / ctctags.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018, 2020 Sadie Powell <sadie@witchery.services>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #pragma once
21
22 #include "event.h"
23 #include "modules/cap.h"
24
25 namespace CTCTags
26 {
27         class CapReference;
28         class EventListener;
29         class TagMessage;
30         class TagMessageDetails;
31 }
32
33 class CTCTags::CapReference : public Cap::Reference
34 {
35  public:
36         CapReference(Module* mod)
37                 : Cap::Reference(mod, "message-tags")
38         {
39         }
40 };
41
42 class CTCTags::TagMessage : public ClientProtocol::Message
43 {
44 private:
45         void PushTarget(const char* target, char status)
46         {
47                 if (status)
48                 {
49                         std::string rawtarget(1, status);
50                         rawtarget.append(target);
51                         PushParam(rawtarget);
52                 }
53                 else
54                         PushParam(target);
55         }
56
57  public:
58         TagMessage(User* source, const Channel* targetchan, const ClientProtocol::TagMap& Tags, char status = 0)
59                 : ClientProtocol::Message("TAGMSG", source)
60         {
61                 PushTarget(targetchan->name.c_str(), status);
62                 AddTags(Tags);
63         }
64
65         TagMessage(User* source, const User* targetuser, const ClientProtocol::TagMap& Tags)
66                 : ClientProtocol::Message("TAGMSG", source)
67         {
68                 if (targetuser->registered & REG_NICK)
69                         PushParamRef(targetuser->nick);
70                 else
71                         PushParam("*");
72                 AddTags(Tags);
73         }
74
75         TagMessage(User* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
76                 : ClientProtocol::Message("TAGMSG", source)
77         {
78                 PushTarget(targetstr, status);
79                 AddTags(Tags);
80         }
81
82         TagMessage(const char* source, const char* targetstr, const ClientProtocol::TagMap& Tags, char status = 0)
83                 : ClientProtocol::Message("TAGMSG", source)
84         {
85                 PushTarget(targetstr, status);
86                 AddTags(Tags);
87         }
88 };
89
90 class CTCTags::TagMessageDetails
91 {
92  public:
93         /** Whether to echo the tags at all. */
94         bool echo;
95
96         /* Whether to send the original tags back to clients with echo-message support. */
97         bool echo_original;
98
99         /** Whether to update the source user's idle time. */
100         bool update_idle;
101
102         /** The users who are exempted from receiving this message. */
103         CUList exemptions;
104
105         /** IRCv3 message tags sent to the server by the user. */
106         const ClientProtocol::TagMap tags_in;
107
108         /** IRCv3 message tags sent out to users who get this message. */
109         ClientProtocol::TagMap tags_out;
110
111         TagMessageDetails(const ClientProtocol::TagMap& tags)
112                 : echo(true)
113                 , echo_original(false)
114                 , update_idle(true)
115                 , tags_in(tags)
116         {
117         }
118 };
119
120 class CTCTags::EventListener
121         : public Events::ModuleEventListener
122 {
123  protected:
124         EventListener(Module* mod, unsigned int eventprio = DefaultPriority)
125                 : ModuleEventListener(mod, "event/tagmsg", eventprio)
126         {
127         }
128
129  public:
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
133          *               glob mask.
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.
138          */
139         virtual ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, TagMessageDetails& details) { return MOD_RES_PASSTHRU; }
140
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
144          *               glob mask.
145          * @param details Details about the message such as the message tags or whether to echo. See the
146          *                TagMessageDetails class for more information.
147          */
148         virtual void OnUserPostTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
149
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
153          *               glob mask.
154          * @param details Details about the message such as the message tags or whether to echo. See the
155          *                TagMessageDetails class for more information.
156          */
157         virtual void OnUserTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
158
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
162          *               glob mask.
163          * @param details Details about the message such as the message tags or whether to echo. See the
164          *                TagMessageDetails class for more information.
165          */
166         virtual void OnUserTagMessageBlocked(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
167 };