diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -1,7 +1,6 @@ #include <string> #include "include/toml.hpp" #include "include/json.hpp" -#include <boost/asio.hpp> #include <tgbot/tgbot.h> #include <cpr/cpr.h> @@ -14,17 +13,15 @@ int main() { TgBot::Bot bot(config["telegram"]["apikey"].value_or("")); - bot.getEvents().onAnyMessage([&bot, &config](TgBot::Message::Ptr message){ + bot.getEvents().onAnyMessage([&bot, &config](TgBot::Message::Ptr const &message){ std::istringstream msg(message->text); std::string command, commandtmp, arguments; - std::cout << "incomming Message: " << message->text << " from " << message->chat->username << "\n"; - std::getline(msg, commandtmp, ' '); std::getline(msg, arguments); - //std::cout << "command: " << commandtmp << "\n"; - if(!(commandtmp.at(0) == '/')){ + + if(commandtmp.at(0) != '/'){ return 0; } else{ command = commandtmp.substr(1, commandtmp.length()-1); @@ -36,10 +33,11 @@ int main() { request["session"] = std::to_string(message->from->id); - cpr::Response r = cpr::Post(cpr::Url{config["n_core"]["adress"].value_or("localhost:18080")}, + cpr::Response r = cpr::Post(cpr::Url{config["n_core"]["address"].value_or("localhost:18080")}, cpr::Body{request.dump()}); if(r.status_code != 200) { - std::cerr << "Error " << r.status_code << " aborting\n"; + std::cerr << "Server gave back error " << r.status_code << ".\n"; + bot.getApi().sendMessage(message->chat->id, "The Server encountered an Error.\nWe are working on a Fix"); return 1; } @@ -51,29 +49,34 @@ int main() { if(jreply["success"] == true) { - for (auto x : jreply["reply"].items()) { + for (auto const &x : jreply["reply"].items()) { if (x.value().at("annotations").at(0).at("type") == "none") { outMessage += x.value().at("text"); } else if (x.value().at("annotations").at(0).at("type") == "bold") { outMessage.append("<b>").append(x.value().at("text")).append("</b>"); - } else if (x.value().at("annotations").at(0).at("type") == "link") { + } else if (x.value().at("annotations").at(0).at("type") == "underline") { outMessage.append("<u>").append(x.value().at("text")).append("</u>"); } else if (x.value().at("annotations").at(0).at("type") == "italic") { outMessage.append("<i>").append(x.value().at("text")).append("</i>"); } else if (x.value().at("annotations").at(0).at("type") == "strikethrough") { outMessage.append("<strike>").append(x.value().at("text")).append("</strike>"); } else if (x.value().at("annotations").at(0).at("type") == "link") { - outMessage.append("<u>").append(x.value().at("text")).append("</u>"); + outMessage.append("<a href=\"").append(x.value().at("text")).append("\" >").append(x.value().at("annotations").at(0).at("extra").at("annotations").at("text").dump()).append("</a>"); } else if (x.value().at("annotations").at(0).at("type") == "command") { outMessage.append("/").append(x.value().at("text")); + } else if (x.value().at("annotations").at(0).at("type") == "attachment") { + outMessage =+ "Attachments are unfortunately not supported"; } } - bot.getApi().sendMessage(message->chat->id, outMessage, false, 0, nullptr, "HTML"); + if(!outMessage.empty()) { + bot.getApi().sendMessage(message->chat->id, outMessage, false, 0, nullptr, "HTML"); + } } else { - bot.getApi().sendMessage(message->chat->id, "Command was not successfully executed."); + outMessage.append("Command was not successfully executed.\n").append(jreply["reply"].at(0).at("text")); + bot.getApi().sendMessage(message->chat->id, outMessage); } return 0; }); |