]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/ctctags.h
b260feadfe6231725efa1672013dbea43c024538
[user/henk/code/inspircd.git] / include / modules / ctctags.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 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
24 namespace CTCTags
25 {
26         class EventListener;
27         class TagMessage;
28         class TagMessageDetails;
29 }
30
31 class CTCTags::TagMessage : public ClientProtocol::Message
32 {
33  public:
34         TagMessage(User* source, const Channel* targetchan, const ClientProtocol::TagMap& Tags)
35                 : ClientProtocol::Message("TAGMSG", source)
36         {
37                 PushParamRef(targetchan->name);
38                 AddTags(Tags);
39         }
40
41         TagMessage(User* source, const User* targetuser, const ClientProtocol::TagMap& Tags)
42                 : ClientProtocol::Message("TAGMSG", source)
43         {
44                 if (targetuser->registered & REG_NICK)
45                         PushParamRef(targetuser->nick);
46                 else
47                         PushParam("*");
48                 AddTags(Tags);
49         }
50
51         TagMessage(User* source, const char* targetstr, const ClientProtocol::TagMap& Tags)
52                 : ClientProtocol::Message("TAGMSG", source)
53         {
54                 PushParam(targetstr);
55                 AddTags(Tags);
56         }
57 };
58
59 class CTCTags::TagMessageDetails
60 {
61  public:
62         /** Whether to echo the tags at all. */
63         bool echo;
64
65         /* Whether to send the original tags back to clients with echo-message support. */
66         bool echo_original;
67
68         /** The users who are exempted from receiving this message. */
69         CUList exemptions;
70
71         /** IRCv3 message tags sent to the server by the user. */
72         const ClientProtocol::TagMap tags_in;
73
74         /** IRCv3 message tags sent out to users who get this message. */
75         ClientProtocol::TagMap tags_out;
76
77         TagMessageDetails(const ClientProtocol::TagMap& tags)
78                 : echo(true)
79                 , echo_original(false)
80                 , tags_in(tags)
81         {
82         }
83 };
84
85 class CTCTags::EventListener
86         : public Events::ModuleEventListener
87 {
88  protected:
89         EventListener(Module* mod, unsigned int eventprio = DefaultPriority)
90                 : ModuleEventListener(mod, "event/tagmsg", eventprio)
91         {
92         }
93
94  public:
95         /** Called before a user sends a tag message to a channel, a user, or a server glob mask.
96          * @param user The user sending the message.
97          * @param target The target of the message. This can either be a channel, a user, or a server
98          *               glob mask.
99          * @param details Details about the message such as the message tags or whether to echo. See the
100          *                TagMessageDetails class for more information.
101          * @return MOD_RES_ALLOW to explicitly allow the message, MOD_RES_DENY to explicitly deny the
102          *         message, or MOD_RES_PASSTHRU to let another module handle the event.
103          */
104         virtual ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, TagMessageDetails& details) { return MOD_RES_PASSTHRU; }
105         
106         /** Called immediately after a user sends a tag message to a channel, a user, or a server glob mask.
107          * @param user The user sending the message.
108          * @param target The target of the message. This can either be a channel, a user, or a server
109          *               glob mask.
110          * @param details Details about the message such as the message tags or whether to echo. See the
111          *                TagMessageDetails class for more information.
112          */
113         virtual void OnUserPostTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
114
115         /** Called immediately before a user sends a tag message to a channel, a user, or a server glob mask.
116          * @param user The user sending the message.
117          * @param target The target of the message. This can either be a channel, a user, or a server
118          *               glob mask.
119          * @param details Details about the message such as the message tags or whether to echo. See the
120          *                TagMessageDetails class for more information.
121          */
122         virtual void OnUserTagMessage(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
123
124         /** Called when a tag message sent by a user to a channel, a user, or a server glob mask is blocked.
125          * @param user The user sending the message.
126          * @param target The target of the message. This can either be a channel, a user, or a server
127          *               glob mask.
128          * @param details Details about the message such as the message tags or whether to echo. See the
129          *                TagMessageDetails class for more information.
130          */
131         virtual void OnUserTagMessageBlocked(User* user, const MessageTarget& target, const TagMessageDetails& details) { }
132 };