diff options
author | Sadie Powell <sadie@witchery.services> | 2024-02-22 14:14:23 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-02-22 14:14:23 +0000 |
commit | 9789c3bd8cb3d4de41c07a6c81abdb55652a800d (patch) | |
tree | 6f325c5279b96e8692ae37f97fd3af566ee5c8f7 /src | |
parent | a75afb597b8b4f7e342c393bc3dea868e66f9b4c (diff) |
Deduplicate User::SendMessage.
Diffstat (limited to 'src')
-rw-r--r-- | src/users.cpp | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/src/users.cpp b/src/users.cpp index 84a5173a4..956d77b9c 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -332,48 +332,42 @@ void User::SendMessage(BotInfo *source, const char *fmt, ...) va_end(args); } -void User::SendMessage(BotInfo *source, const Anope::string &msg) +namespace { - const char *translated_message = Language::Translate(this, msg.c_str()); - - /* Send privmsg instead of notice if: - * - UsePrivmsg is enabled - * - The user is not registered and NSDefMsg is enabled - * - The user is registered and has set /ns set msg on - */ - bool send_privmsg = Config->UsePrivmsg && ((!this->nc && Config->DefPrivmsg) || (this->nc && this->nc->HasExt("MSG"))); - sepstream sep(translated_message, '\n', true); - for (Anope::string tok; sep.GetToken(tok);) + void SendMessageInternal(BotInfo *source, User* target, const Anope::string &msg, const Anope::map<Anope::string> &tags) { - if (send_privmsg) - IRCD->SendPrivmsgInternal(source, this->GetUID(), tok); - else - IRCD->SendNoticeInternal(source, this->GetUID(), tok); + const char *translated_message = Language::Translate(target, msg.c_str()); + + /* Send privmsg instead of notice if: + * - UsePrivmsg is enabled + * - The user is not registered and NSDefMsg is enabled + * - The user is registered and has set /ns set msg on + */ + auto account = target->Account(); + bool send_privmsg = Config->UsePrivmsg && ((!account && Config->DefPrivmsg) || (account && account->HasExt("MSG"))); + sepstream sep(translated_message, '\n', true); + for (Anope::string tok; sep.GetToken(tok);) + { + if (send_privmsg) + IRCD->SendPrivmsgInternal(source, target->GetUID(), tok, tags); + else + IRCD->SendNoticeInternal(source, target->GetUID(), tok, tags); + } } } +void User::SendMessage(BotInfo *source, const Anope::string &msg) +{ + SendMessageInternal(source, this, msg, {}); +} + void User::SendMessage(CommandSource& source, const Anope::string &msg) { Anope::map<Anope::string> tags; if (!source.msgid.empty()) tags["+draft/reply"] = source.msgid; - const char *translated_message = Language::Translate(this, msg.c_str()); - - /* Send privmsg instead of notice if: - * - UsePrivmsg is enabled - * - The user is not registered and NSDefMsg is enabled - * - The user is registered and has set /ns set msg on - */ - bool send_privmsg = Config->UsePrivmsg && ((!this->nc && Config->DefPrivmsg) || (this->nc && this->nc->HasExt("MSG"))); - sepstream sep(translated_message, '\n', true); - for (Anope::string tok; sep.GetToken(tok);) - { - if (send_privmsg) - IRCD->SendPrivmsgInternal(*source.service, this->GetUID(), tok, tags); - else - IRCD->SendNoticeInternal(*source.service, this->GetUID(), tok, tags); - } + SendMessageInternal(*source.service, this, msg, tags); } void User::Identify(NickAlias *na) |