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->GetServerName());
95 msg.PushParamRef(command->name);
99 msg.PushParam(description);
100 SendInternal(user, msg);
103 template<typename T1>
104 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const std::string& description)
106 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
108 msg.PushParamRef(command->name);
112 msg.PushParam(ConvToStr(p1));
113 msg.PushParam(description);
114 SendInternal(user, msg);
117 template<typename T1, typename T2>
118 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
119 const std::string& description)
121 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
123 msg.PushParamRef(command->name);
127 msg.PushParam(ConvToStr(p1));
128 msg.PushParam(ConvToStr(p2));
129 msg.PushParam(description);
130 SendInternal(user, msg);
133 template<typename T1, typename T2, typename T3>
134 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
135 const T3& p3, const std::string& description)
137 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
139 msg.PushParamRef(command->name);
143 msg.PushParam(ConvToStr(p1));
144 msg.PushParam(ConvToStr(p2));
145 msg.PushParam(ConvToStr(p3));
146 msg.PushParam(description);
147 SendInternal(user, msg);
150 template<typename T1, typename T2, typename T3, typename T4>
151 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
152 const T3& p3, const T4& p4, const std::string& description)
154 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
156 msg.PushParamRef(command->name);
160 msg.PushParam(ConvToStr(p1));
161 msg.PushParam(ConvToStr(p2));
162 msg.PushParam(ConvToStr(p3));
163 msg.PushParam(ConvToStr(p4));
164 msg.PushParam(description);
165 SendInternal(user, msg);
168 template<typename T1, typename T2, typename T3, typename T4, typename T5>
169 void Send(LocalUser* user, Command* command, const std::string& code, const T1& p1, const T2& p2,
170 const T3& p3, const T4& p4, const T5& p5, const std::string& description)
172 ClientProtocol::Message msg(cmd.c_str(), ServerInstance->Config->GetServerName());
174 msg.PushParamRef(command->name);
178 msg.PushParam(ConvToStr(p1));
179 msg.PushParam(ConvToStr(p2));
180 msg.PushParam(ConvToStr(p3));
181 msg.PushParam(ConvToStr(p4));
182 msg.PushParam(ConvToStr(p5));
183 msg.PushParam(description);
184 SendInternal(user, msg);
188 * Sends a standard reply to the specified user if they have the specified cap
189 * or a notice if they do not.
190 * @param user The user to send the reply to.
191 * @param command The command that the reply relates to.
192 * @param code A machine readable code for this reply.
193 * @param description A human readable description of this reply.
195 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
196 const std::string& description)
199 Send(user, command, code, description);
201 SendNoticeInternal(user, command, description);
204 template<typename T1>
205 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
206 const T1& p1, const std::string& description)
209 Send(user, command, code, p1, description);
211 SendNoticeInternal(user, command, description);
214 template<typename T1, typename T2>
215 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
216 const T1& p1, const T2& p2, const std::string& description)
219 Send(user, command, code, p1, p2, description);
221 SendNoticeInternal(user, command, description);
224 template<typename T1, typename T2, typename T3>
225 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
226 const T1& p1, const T2& p2, const T3& p3, const std::string& description)
229 Send(user, command, code, p1, p2, p3, description);
231 SendNoticeInternal(user, command, description);
234 template<typename T1, typename T2, typename T3, typename T4>
235 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
236 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const std::string& description)
239 Send(user, command, code, p1, p2, p3, p4, description);
241 SendNoticeInternal(user, command, description);
244 template<typename T1, typename T2, typename T3, typename T4, typename T5>
245 void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
246 const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5, const std::string& description)
249 Send(user, command, code, p1, p2, p3, p4, p5, description);
251 SendNoticeInternal(user, command, description);
255 /** Sends a FAIL standard reply. */
256 class IRCv3::Replies::Fail
257 : public IRCv3::Replies::Reply
260 /** Initializes a new instance of the Fail class.
261 * @param Creator The module which created this instance.
263 Fail(Module* Creator)
264 : Reply(Creator, "FAIL")
269 /** Sends a NOTE standard reply. */
270 class IRCv3::Replies::Note
271 : public IRCv3::Replies::Reply
274 /** Initializes a new instance of the Note class.
275 * @param Creator The module which created this instance.
277 Note(Module* Creator)
278 : Reply(Creator, "NOTE")
283 /** Sends a WARN standard reply. */
284 class IRCv3::Replies::Warn
285 : public IRCv3::Replies::Reply
288 /** Initializes a new instance of the Warn class.
289 * @param Creator The module which created this instance.
291 Warn(Module* Creator)
292 : Reply(Creator, "WARN")