diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-08-24 22:34:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-08-24 22:34:23 +0300 |
commit | c4ce93f62d1d4e857c5f763cbee063a4dae10d59 (patch) | |
tree | 1a1a178426583223450ca247006f6f67eef0d6e8 | |
parent | d9dc86b8dce433947c81ba87ad0bad83d4bc96f6 (diff) | |
download | mv-c4ce93f62d1d4e857c5f763cbee063a4dae10d59.tar.gz mv-c4ce93f62d1d4e857c5f763cbee063a4dae10d59.tar.bz2 mv-c4ce93f62d1d4e857c5f763cbee063a4dae10d59.tar.xz mv-c4ce93f62d1d4e857c5f763cbee063a4dae10d59.zip |
Simplify /unignore and /erase chat commands.
-rw-r--r-- | src/actions/commands.cpp | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 2b4c40b0e..034dafdfb 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -136,7 +136,7 @@ impHandler(chatIgnore) return true; } -impHandler(chatUnignore) +static std::string getNick(const InputEvent &event) { std::string args = event.args; if (args.empty()) @@ -146,10 +146,38 @@ impHandler(chatUnignore) { // TRANSLATORS: change relation event.tab->chatLog(_("Please specify a name."), ChatMsgType::BY_SERVER); - return false; + return std::string(); } args = whisper->getNick(); } + return args; +} + +static void reportRelation(const InputEvent &event, + const PlayerRelation::Relation &rel, + const std::string &str1, + const std::string &str2) +{ + if (event.tab) + { + if (player_relations.getRelation(args) == rel) + { + // TRANSLATORS: unignore command + event.tab->chatLog(str1, ChatMsgType::BY_SERVER); + } + else + { + // TRANSLATORS: unignore command + event.tab->chatLog(str2, ChatMsgType::BY_SERVER); + } + } +} + +impHandler(chatUnignore) +{ + std::string args = getNick(event); + if (args.empty()) + return false; const PlayerRelation::Relation rel = player_relations.getRelation(args); if (rel != PlayerRelation::NEUTRAL && rel != PlayerRelation::FRIEND) @@ -166,38 +194,20 @@ impHandler(chatUnignore) return true; } - if (event.tab) - { - if (player_relations.getRelation(args) == PlayerRelation::NEUTRAL) - { - // TRANSLATORS: unignore command - event.tab->chatLog(_("Player no longer ignored!"), - ChatMsgType::BY_SERVER); - } - else - { - // TRANSLATORS: unignore command - event.tab->chatLog(_("Player could not be unignored!"), - ChatMsgType::BY_SERVER); - } - } + reportRelation(event, + PlayerRelation::NEUTRAL, + // TRANSLATORS: unignore command + _("Player no longer ignored!"), + // TRANSLATORS: unignore command + _("Player could not be unignored!")); return true; } impHandler(chatErase) { - std::string args = event.args; + std::string args = getNick(event); if (args.empty()) - { - WhisperTab *const whisper = dynamic_cast<WhisperTab* const>(event.tab); - if (!whisper || whisper->getNick().empty()) - { - // TRANSLATORS: change relation - event.tab->chatLog(_("Please specify a name."), ChatMsgType::BY_SERVER); - return false; - } - args = whisper->getNick(); - } + return false; if (player_relations.getRelation(args) == PlayerRelation::ERASED) { @@ -213,21 +223,12 @@ impHandler(chatErase) player_relations.setRelation(args, PlayerRelation::ERASED); } - if (event.tab) - { - if (player_relations.getRelation(args) == PlayerRelation::ERASED) - { - // TRANSLATORS: erase command - event.tab->chatLog(_("Player successfully erased!"), - ChatMsgType::BY_SERVER); - } - else - { - // TRANSLATORS: erase command - event.tab->chatLog(_("Player could not be erased!"), - ChatMsgType::BY_SERVER); - } - } + reportRelation(event, + PlayerRelation::ERASED, + // TRANSLATORS: erase command + _("Player no longer erased!"), + // TRANSLATORS: erase command + _("Player could not be erased!")); return true; } |