From d95be0a5165cf3cee3d1feedab1bdbdf21e5e419 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 18 Aug 2024 16:04:36 +0100 Subject: Add a formatting overload to {Membership,User}::Write(Remote)Notice. --- include/membership.h | 10 ++++++++++ include/modules/ircv3_replies.h | 4 ++-- include/users.h | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/membership.h b/include/membership.h index 1d08ec027..f54ef32e0 100644 --- a/include/membership.h +++ b/include/membership.h @@ -134,4 +134,14 @@ public: * @param text The contents of the message to send. */ void WriteNotice(const std::string& text) const; + + /** Sends a server notice to this user in the context of this channel. + * @param text A format string to format and then send. + * @param p One or more arguments to format the string with. + */ + template + void WriteNotice(const char* text, Param&&... p) + { + WriteNotice(fmt::format(text, std::forward(p)...)); + } }; diff --git a/include/modules/ircv3_replies.h b/include/modules/ircv3_replies.h index 4bfc8a30b..c92e257e9 100644 --- a/include/modules/ircv3_replies.h +++ b/include/modules/ircv3_replies.h @@ -67,9 +67,9 @@ private: void SendNoticeInternal(LocalUser* user, const Command* command, const std::string& description) { if (command) - user->WriteNotice(INSP_FORMAT("*** {}: {}", command->name, description)); + user->WriteNotice("*** {}: {}", command->name, description); else - user->WriteNotice(INSP_FORMAT("*** {}", description)); + user->WriteNotice("*** {}", description); } protected: diff --git a/include/users.h b/include/users.h index f6dd59a0d..b7be744eb 100644 --- a/include/users.h +++ b/include/users.h @@ -665,11 +665,31 @@ public: */ void WriteNotice(const std::string& text); + /** Sends a server notice to this user. + * @param text A format string to format and then send. + * @param p One or more arguments to format the string with. + */ + template + void WriteNotice(const char* text, Param&&... p) + { + WriteNotice(fmt::format(text, std::forward(p)...)); + } + /** Sends a server notice from the local server to the user. * @param text The message to send. */ virtual void WriteRemoteNotice(const std::string& text); + /** Sends a server notice to this user. + * @param text A format string to format and then send. + * @param p One or more arguments to format the string with. + */ + template + void WriteRemoteNotice(const char* text, Param&&... p) + { + WriteRemoteNotice(fmt::format(text, std::forward(p)...)); + } + /** Sends a notice to this user. * @param numeric The numeric to send. */ -- cgit v1.3.1-10-gc9f91