This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
HelloBot/SimpleBot/MessageHandler.cpp

39 lines
957 B
C++
Raw Permalink Normal View History

#include "MessageHandler.h"
#include <sstream>
void MessageHandler::replyUserUnknown(const tgbot::types::Message &message, const tgbot::methods::Api &api)
{
api.sendMessage(std::to_string(message.chat.id), "Sorry, I don't know who you are.");
}
void MessageHandler::handle(const tgbot::types::Message &message, const tgbot::methods::Api &api)
{
if (message.from == nullptr || knownUsers.find(*message.from->username) == knownUsers.cend())
{
replyUserUnknown(message, api);
return;
}
2018-03-29 12:06:10 +00:00
std::ostringstream logMessage;
logMessage << message.from->firstName
<< " (" << *message.from->username << "): "
2018-03-29 12:06:10 +00:00
<< (message.text != nullptr ? *message.text : "<no text>");
api.getLogger().info(logMessage.str());
std::ostringstream reply;
reply << "You said";
if (message.text != nullptr)
{
reply << ": '" << *message.text << "'";
}
else
{
reply << " illegible things";
}
api.sendMessage(std::to_string(message.chat.id), reply.str());
}