2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019-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/>.
22 #include "modules/cap.h"
36 /** Reference to the inspircd.org/standard-replies cap. */
37 class IRCv3::Replies::CapReference
38 : public Cap::Reference
41 CapReference(Module* mod)
42 : Cap::Reference(mod, "inspircd.org/standard-replies")
47 /** Base class for standard replies. */
48 class IRCv3::Replies::Reply
51 /** The name of the command for this reply. */
52 const std::string cmd;
54 /** The event provider for this reply. */
55 ClientProtocol::EventProvider evprov;
57 /** Wraps a message in an event and sends it to a user.
58 * @param user The user to send the message to.
59 * @param msg The message to send to the user.
61 void SendInternal(LocalUser* user, ClientProtocol::Message& msg)
63 ClientProtocol::Event ev(evprov, msg);
67 void SendNoticeInternal(LocalUser* user, Command* command, const std::string& description)
69 user->WriteNotice(InspIRCd::Format("*** %s: %s", command->name.c_str(), description.c_str()));
73 /** Initializes a new instance of the Reply class.
74 * @param Creator The module which created this instance.
75 * @param Cmd The name of the command to reply with.
77 Reply(Module* Creator, const std::string& Cmd)
79 , evprov(Creator, Cmd)
85 * Sends a standard reply to the specified user.
86 * @param user The user to send the reply to.
87 * @param command The command that the reply relates to.
88 * @param code A machine readable code for this reply.
89 * @param description A human readable description of this reply.
91 void Send(LocalUser* user, Command* command, const std::string& code, const std::string& description)
93 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
94 msg.PushParamRef(command->name);
96 msg.PushParam(description);
97 SendInternal(user, msg);
100 template<typename T1>
101 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const std::string& description)
103 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
104 msg.PushParamRef(command->name);
106 msg.PushParam(ConvToStr(p1));
107 msg.PushParam(description);
108 SendInternal(user, msg);
111 template<typename T1, typename T2>
112 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
113 const std::string& description)
115 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
116 msg.PushParamRef(command->name);
118 msg.PushParam(ConvToStr(p1));
119 msg.PushParam(ConvToStr(p2));
120 msg.PushParam(description);
121 SendInternal(user, msg);
124 template<typename T1, typename T2, typename T3>
125 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
126 const T3& p3, const std::string& description)
128 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
129 msg.PushParamRef(command->name);
131 msg.PushParam(ConvToStr(p1));
132 msg.PushParam(ConvToStr(p2));
133 msg.PushParam(ConvToStr(p3));
134 msg.PushParam(description);
135 SendInternal(user, msg);
138 template<typename T1, typename T2, typename T3, typename T4>
139 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
140 const T3& p3, const T4& p4, const std::string& description)
142 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
143 msg.PushParamRef(command->name);
145 msg.PushParam(ConvToStr(p1));
146 msg.PushParam(ConvToStr(p2));
147 msg.PushParam(ConvToStr(p3));
148 msg.PushParam(ConvToStr(p4));
149 msg.PushParam(description);
150 SendInternal(user, msg);
153 template<typename T1, typename T2, typename T3, typename T4, typename T5>
154 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
155 const T3& p3, const T4& p4, const T5& p5, const std::string& description)
157 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->ServerName);
159 msg.PushParamRef(command->name);
163 msg.PushParam(ConvToStr(p1));
164 msg.PushParam(ConvToStr(p2));
165 msg.PushParam(ConvToStr(p3));
166 msg.PushParam(ConvToStr(p4));
167 msg.PushParam(ConvToStr(p5));
168 msg.PushParam(description);
169 SendInternal(user, msg);
173 * Sends a standard reply to the specified user if they have the specified cap
174 * or a notice if they do not.
175 * @param user The user to send the reply to.
176 * @param command The command that the reply relates to.
177 * @param code A machine readable code for this reply.
178 * @param description A human readable description of this reply.
180 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
181 const std::string& description)
184 Send(user, command, code, description);
186 SendNoticeInternal(user, command, description);
189 template<typename T1>
190 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
191 const T1& p1, const std::string& description)
194 Send(user, command, code, p1, description);
196 SendNoticeInternal(user, command, description);
199 template<typename T1, typename T2>
200 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
201 const T1& p1, const T2& p2, const std::string& description)
204 Send(user, command, code, p1, p2, description);
206 SendNoticeInternal(user, command, description);
209 template<typename T1, typename T2, typename T3>
210 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
211 const T1& p1, const T2& p2, const T3& p3, const std::string& description)
214 Send(user, command, code, p1, p2, p3, description);
216 SendNoticeInternal(user, command, description);
219 template<typename T1, typename T2, typename T3, typename T4>
220 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
221 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const std::string& description)
224 Send(user, command, code, p1, p2, p3, p4, description);
226 SendNoticeInternal(user, command, description);
229 template<typename T1, typename T2, typename T3, typename T4, typename T5>
230 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
231 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5, const std::string& description)
234 Send(user, command, code, p1, p2, p3, p4, p5, description);
236 SendNoticeInternal(user, command, description);
240 /** Sends a FAIL standard reply. */
241 class IRCv3::Replies::Fail
242 : public IRCv3::Replies::Reply
245 /** Initializes a new instance of the Fail class.
246 * @param Creator The module which created this instance.
248 Fail(Module* Creator)
249 : Reply(Creator, "FAIL")
254 /** Sends a NOTE standard reply. */
255 class IRCv3::Replies::Note
256 : public IRCv3::Replies::Reply
259 /** Initializes a new instance of the Note class.
260 * @param Creator The module which created this instance.
262 Note(Module* Creator)
263 : Reply(Creator, "NOTE")
268 /** Sends a WARN standard reply. */
269 class IRCv3::Replies::Warn
270 : public IRCv3::Replies::Reply
273 /** Initializes a new instance of the Warn class.
274 * @param Creator The module which created this instance.
276 Warn(Module* Creator)
277 : Reply(Creator, "WARN")