diff --git a/include/numeric.h b/include/numeric.h index 5c93d88ad..b821424ca 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -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 + Numeric& push_fmt(const char* text, Args&&... args) + { + push(fmt::format(text, std::forward(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 */ diff --git a/include/numerichelper.h b/include/numerichelper.h index 6be75d3be..6e762bd65 100644 --- a/include/numerichelper.h +++ b/include/numerichelper.h @@ -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); } } diff --git a/src/coremods/core_user/core_user.cpp b/src/coremods/core_user/core_user.cpp index 58d27410d..a47946eac 100644 --- a/src/coremods/core_user/core_user.cpp +++ b/src/coremods/core_user/core_user.cpp @@ -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; } diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp index 5a4a22247..c79a0c760 100644 --- a/src/modules/m_uninvite.cpp +++ b/src/modules/m_uninvite.cpp @@ -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; }