From 41adf75fa42f497e9f0049a786f08f3414ed6cbd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 3 Feb 2016 19:38:05 +0300 Subject: Add chat command /seen for show seen informatin abount nick. --- src/actions/actions.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ src/actions/actions.h | 1 + src/dyetool/actions/actions.cpp | 1 + src/enums/input/inputaction.h | 1 + src/input/inputactionmap.h | 6 ++++++ 5 files changed, 55 insertions(+) diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index 169727b2a..472ea2b6d 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -103,6 +103,7 @@ #include "utils/chatutils.h" #include "utils/delete2.h" #include "utils/gettext.h" +#include "utils/files.h" #include "utils/timer.h" #include "utils/mathutils.h" @@ -1719,4 +1720,49 @@ impHandler(barToChat) return false; } +impHandler(seen) +{ + if (!actorManager) + return false; + + const std::string name = event.args; + if (name.empty()) + return false; + + ChatTab *tab = event.tab; + if (!tab) + tab = localChatTab; + if (!tab) + return false; + + std::string dir = settings.usersDir; + dir.append(stringToHexPath(name)).append("/seen.txt"); + if (Files::existsLocal(dir)) + { + StringVect lines; + Files::loadTextFileLocal(dir, lines); + if (lines.size() < 3) + { + // TRANSLATORS: last seen error + tab->chatLog(_("You not saw this nick."), + ChatMsgType::BY_SERVER); + return true; + } + const std::string message = strprintf( + // TRANSLATORS: last seen message + _("Last seen for %s: %s"), + name.c_str(), + lines[2].c_str()); + tab->chatLog(message, ChatMsgType::BY_SERVER); + } + else + { + // TRANSLATORS: last seen error + tab->chatLog(_("You not saw this nick."), + ChatMsgType::BY_SERVER); + } + + return true; +} + } // namespace Actions diff --git a/src/actions/actions.h b/src/actions/actions.h index 5581fee52..7d583527b 100644 --- a/src/actions/actions.h +++ b/src/actions/actions.h @@ -112,6 +112,7 @@ namespace Actions decHandler(craftKey); decHandler(resetGameModifiers); decHandler(barToChat); + decHandler(seen); } // namespace Actions #undef decHandler diff --git a/src/dyetool/actions/actions.cpp b/src/dyetool/actions/actions.cpp index 834f7d2f9..bcb5bb98d 100644 --- a/src/dyetool/actions/actions.cpp +++ b/src/dyetool/actions/actions.cpp @@ -109,5 +109,6 @@ impHandlerVoid(testInfo) impHandlerVoid(craftKey) impHandlerVoid(resetGameModifiers) impHandlerVoid(barToChat) +impHandlerVoid(seen) } // namespace Actions diff --git a/src/enums/input/inputaction.h b/src/enums/input/inputaction.h index f6837109e..68a11baa3 100644 --- a/src/enums/input/inputaction.h +++ b/src/enums/input/inputaction.h @@ -624,6 +624,7 @@ enumStart(InputAction) IGNORE_PICKUP, RESET_MODIFIERS, BAR_TO_CHAT, + SEEN, TOTAL } enumEnd(InputAction); diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index b8f89c7cd..91b8d8368 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -5233,6 +5233,12 @@ static const InputActionData inputActionData "bartochat", UseArgs_true, Protected_true}, + {"keySeenCmd", + defaultAction(&Actions::seen), + InputCondition::INGAME, + "seen|lastseen", + UseArgs_true, + Protected_true}, }; #undef defaultAction -- cgit v1.2.3-70-g09d2