From 475aa157df7400ce40ef9a5cc4cb441291d45df9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 23 Aug 2014 21:48:59 +0300 Subject: Move chat command /whisper into actions. --- src/actions/chat.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/actions/chat.cpp') diff --git a/src/actions/chat.cpp b/src/actions/chat.cpp index d69895af3..08b3e0014 100644 --- a/src/actions/chat.cpp +++ b/src/actions/chat.cpp @@ -68,6 +68,9 @@ #include "gui/widgets/tabs/chattab.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + #include "debug.h" extern ShortcutWindow *spellShortcutWindow; @@ -154,4 +157,58 @@ impHandler0(scrollChatDown) return false; } +impHandler(msg) +{ + std::string recvnick; + std::string msg; + + if (event.args.substr(0, 1) == "\"") + { + const size_t pos = event.args.find('"', 1); + if (pos != std::string::npos) + { + recvnick = event.args.substr(1, pos - 1); + if (pos + 2 < event.args.length()) + msg = event.args.substr(pos + 2, event.args.length()); + } + } + else + { + const size_t pos = event.args.find(" "); + if (pos != std::string::npos) + { + recvnick = event.args.substr(0, pos); + if (pos + 1 < event.args.length()) + msg = event.args.substr(pos + 1, event.args.length()); + } + else + { + recvnick = std::string(event.args); + msg.clear(); + } + } + + trim(msg); + + if (msg.length() > 0) + { + std::string playerName = localPlayer->getName(); + std::string tempNick = recvnick; + + toLower(playerName); + toLower(tempNick); + + if (tempNick.compare(playerName) == 0 || event.args.empty()) + return true; + + chatWindow->addWhisper(recvnick, msg, ChatMsgType::BY_PLAYER); + } + else + { + // TRANSLATORS: whisper send + event.tab->chatLog(_("Cannot send empty whispers!"), ChatMsgType::BY_SERVER); + } + return true; +} + } // namespace Actions -- cgit v1.2.3-70-g09d2