2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019-2021 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)
70 user->WriteNotice(InspIRCd::Format("*** %s: %s", command->name.c_str(), description.c_str()));
72 user->WriteNotice(InspIRCd::Format("*** %s", description.c_str()));
76 /** Initializes a new instance of the Reply class.
77 * @param Creator The module which created this instance.
78 * @param Cmd The name of the command to reply with.
80 Reply(Module* Creator, const std::string& Cmd)
82 , evprov(Creator, Cmd)
88 * Sends a standard reply to the specified user.
89 * @param user The user to send the reply to.
90 * @param command The command that the reply relates to.
91 * @param code A machine readable code for this reply.
92 * @param description A human readable description of this reply.
94 void Send(LocalUser* user, Command* command, const std::string& code, const std::string& description)
96 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
98 msg.PushParamRef(command->name);
102 msg.PushParam(description);
103 SendInternal(user, msg);
106 template<typename T1>
107 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const std::string& description)
109 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
111 msg.PushParamRef(command->name);
115 msg.PushParam(ConvToStr(p1));
116 msg.PushParam(description);
117 SendInternal(user, msg);
120 template<typename T1, typename T2>
121 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
122 const std::string& description)
124 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
126 msg.PushParamRef(command->name);
130 msg.PushParam(ConvToStr(p1));
131 msg.PushParam(ConvToStr(p2));
132 msg.PushParam(description);
133 SendInternal(user, msg);
136 template<typename T1, typename T2, typename T3>
137 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
138 const T3& p3, const std::string& description)
140 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
142 msg.PushParamRef(command->name);
146 msg.PushParam(ConvToStr(p1));
147 msg.PushParam(ConvToStr(p2));
148 msg.PushParam(ConvToStr(p3));
149 msg.PushParam(description);
150 SendInternal(user, msg);
153 template<typename T1, typename T2, typename T3, typename T4>
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 std::string& description)
157 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
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(description);
168 SendInternal(user, msg);
171 template<typename T1, typename T2, typename T3, typename T4, typename T5>
172 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
173 const T3& p3, const T4& p4, const T5& p5, const std::string& description)
175 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
177 msg.PushParamRef(command->name);
181 msg.PushParam(ConvToStr(p1));
182 msg.PushParam(ConvToStr(p2));
183 msg.PushParam(ConvToStr(p3));
184 msg.PushParam(ConvToStr(p4));
185 msg.PushParam(ConvToStr(p5));
186 msg.PushParam(description);
187 SendInternal(user, msg);
191 * Sends a standard reply to the specified user if they have the specified cap
192 * or a notice if they do not.
193 * @param user The user to send the reply to.
194 * @param command The command that the reply relates to.
195 * @param code A machine readable code for this reply.
196 * @param description A human readable description of this reply.
198 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
199 const std::string& description)
202 Send(user, command, code, description);
204 SendNoticeInternal(user, command, description);
207 template<typename T1>
208 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
209 const T1& p1, const std::string& description)
212 Send(user, command, code, p1, description);
214 SendNoticeInternal(user, command, description);
217 template<typename T1, typename T2>
218 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
219 const T1& p1, const T2& p2, const std::string& description)
222 Send(user, command, code, p1, p2, description);
224 SendNoticeInternal(user, command, description);
227 template<typename T1, typename T2, typename T3>
228 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
229 const T1& p1, const T2& p2, const T3& p3, const std::string& description)
232 Send(user, command, code, p1, p2, p3, description);
234 SendNoticeInternal(user, command, description);
237 template<typename T1, typename T2, typename T3, typename T4>
238 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
239 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const std::string& description)
242 Send(user, command, code, p1, p2, p3, p4, description);
244 SendNoticeInternal(user, command, description);
247 template<typename T1, typename T2, typename T3, typename T4, typename T5>
248 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
249 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5, const std::string& description)
252 Send(user, command, code, p1, p2, p3, p4, p5, description);
254 SendNoticeInternal(user, command, description);
258 /** Sends a FAIL standard reply. */
259 class IRCv3::Replies::Fail
260 : public IRCv3::Replies::Reply
263 /** Initializes a new instance of the Fail class.
264 * @param Creator The module which created this instance.
266 Fail(Module* Creator)
267 : Reply(Creator, "FAIL")
272 /** Sends a NOTE standard reply. */
273 class IRCv3::Replies::Note
274 : public IRCv3::Replies::Reply
277 /** Initializes a new instance of the Note class.
278 * @param Creator The module which created this instance.
280 Note(Module* Creator)
281 : Reply(Creator, "NOTE")
286 /** Sends a WARN standard reply. */
287 class IRCv3::Replies::Warn
288 : public IRCv3::Replies::Reply
291 /** Initializes a new instance of the Warn class.
292 * @param Creator The module which created this instance.
294 Warn(Module* Creator)
295 : Reply(Creator, "WARN")