Add Numeric::push_fmt(...) as shorthand for push(INSP_FORMAT(...)).

This commit is contained in:
Sadie Powell 2024-08-18 16:30:55 +01:00
parent d95be0a516
commit 15e7db5a21
4 changed files with 23 additions and 12 deletions

View File

@ -128,6 +128,17 @@ public:
return *this;
}
/** Formats the string with the specified arguments and adds them to the numeric.
* @param text A format string to format and then push.
* @param p One or more arguments to format the string with.
*/
template <typename... Args>
Numeric& push_fmt(const char* text, Args&&... args)
{
push(fmt::format(text, std::forward<Args>(args)...));
return *this;
}
/** Set the source server of the numeric. The source server defaults to the local server.
* @param server Server to set as source
*/

View File

@ -54,8 +54,8 @@ public:
: Numeric(ERR_CANNOTSENDTOCHAN)
{
push(chan->name);
push(INSP_FORMAT("You cannot send {} to this channel whilst the +{} ({}) mode is set.",
what, mh->GetModeChar(), mh->name));
push_fmt("You cannot send {} to this channel whilst the +{} ({}) mode is set.", what,
mh->GetModeChar(), mh->name);
}
#ifdef INSPIRCD_EXTBAN
@ -63,8 +63,8 @@ public:
: Numeric(ERR_CANNOTSENDTOCHAN)
{
push(chan->name);
push(INSP_FORMAT("You cannot send {} to this channel whilst {} {}: ({}) extban is set matching you.",
what, strchr("AEIOUaeiou", xb.GetLetter()) ? "an" : "a", xb.GetLetter(), xb.GetName()));
push_fmt("You cannot send {} to this channel whilst {} {}: ({}) extban is set matching you.",
what, strchr("AEIOUaeiou", xb.GetLetter()) ? "an" : "a", xb.GetLetter(), xb.GetName());
}
#endif
@ -79,8 +79,8 @@ public:
: Numeric(ERR_CANNOTSENDTOUSER)
{
push(user->connected & User::CONN_NICK ? user->nick : "*");
push(INSP_FORMAT("You cannot send {} to this user whilst {} have the +{} ({}) mode set.",
what, self ? "you" : "they", mh->GetModeChar(), mh->name));
push_fmt("You cannot send {} to this user whilst {} have the +{} ({}) mode set.",
what, self ? "you" : "they", mh->GetModeChar(), mh->name);
}
};
@ -95,9 +95,9 @@ public:
const PrefixMode* pm = ServerInstance->Modes.FindNearestPrefixMode(rank);
if (pm)
push(INSP_FORMAT("You must be a channel {} or higher to {}.", pm->name, message));
push_fmt("You must be a channel {} or higher to {}.", pm->name, message);
else
push(INSP_FORMAT("You do not have the required channel privileges to {}.", message));
push_fmt("You do not have the required channel privileges to {}.", message);
}
};
@ -119,12 +119,12 @@ private:
if (!syntax.empty())
{
// If the mode has a syntax hint we include it in the message.
push(INSP_FORMAT("Invalid {} mode parameter. Syntax: {}.", mode->name, syntax));
push_fmt("Invalid {} mode parameter. Syntax: {}.", mode->name, syntax);
}
else
{
// Otherwise, send it without.
push(INSP_FORMAT("Invalid {} mode parameter.", mode->name));
push_fmt("Invalid {} mode parameter.", mode->name);
}
}

View File

@ -211,7 +211,7 @@ public:
klass->GetName(), error);
errnum = ERR_PASSWDMISMATCH;
errnum->push(INSP_FORMAT("A password is required and {}.", error));
errnum->push_fmt("A password is required and {}.", error);
return MOD_RES_DENY;
}

View File

@ -95,7 +95,7 @@ public:
{
Numeric::Numeric n(ERR_NOTINVITED);
n.SetServer(user->server);
n.push(u->nick).push(c->name).push(INSP_FORMAT("Is not invited to channel {}", c->name));
n.push(u->nick, c->name).push_fmt("Is not invited to channel {}", c->name);
user->WriteRemoteNumeric(n);
return CmdResult::FAILURE;
}