diff options
-rw-r--r-- | include/commands.h | 1 | ||||
-rw-r--r-- | include/users.h | 1 | ||||
-rw-r--r-- | src/command.cpp | 7 | ||||
-rw-r--r-- | src/users.cpp | 24 |
4 files changed, 32 insertions, 1 deletions
diff --git a/include/commands.h b/include/commands.h index 1778dd4d9..ed318e60a 100644 --- a/include/commands.h +++ b/include/commands.h @@ -44,6 +44,7 @@ struct CoreExport CommandReply { virtual ~CommandReply() = default; virtual void SendMessage(BotInfo *source, const Anope::string &msg) = 0; + virtual void SendMessage(CommandSource& source, const Anope::string &msg); }; /* The source for a command */ diff --git a/include/users.h b/include/users.h index 2c9779ea3..b33cf2916 100644 --- a/include/users.h +++ b/include/users.h @@ -193,6 +193,7 @@ public: */ void SendMessage(BotInfo *source, const char *fmt, ...) ATTR_FORMAT(3, 4); void SendMessage(BotInfo *source, const Anope::string &msg) override; + void SendMessage(CommandSource& source, const Anope::string &msg) override; /** Identify the user to a nick. * updates last_seen, logs the user in, diff --git a/src/command.cpp b/src/command.cpp index 2ac6cb7d7..dc24dac0b 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -17,6 +17,11 @@ #include "regchannel.h" #include "channels.h" +void CommandReply::SendMessage(CommandSource& source, const Anope::string &msg) +{ + SendMessage(source.service, msg); +} + CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi, const Anope::string &m) : nick(n) , u(user) @@ -119,7 +124,7 @@ void CommandSource::Reply(const Anope::string &message) sepstream sep(translated_message, '\n', true); Anope::string tok; while (sep.GetToken(tok)) - this->reply->SendMessage(this->service, tok); + this->reply->SendMessage(*this, tok); } Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(o) diff --git a/src/users.cpp b/src/users.cpp index 452d84706..84a5173a4 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -352,6 +352,30 @@ void User::SendMessage(BotInfo *source, const Anope::string &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); + } +} + void User::Identify(NickAlias *na) { if (this->nick.equals_ci(na->nick)) |