From 2f8ff5fc79e394b95bafdb5931f2cdddb8a7ae1c Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Wed, 26 Aug 2020 11:20:44 +0200 Subject: Extended extra field of annotations to be an list of text-annotation pairs as well Fixed CMake Boost findings --- src/Response.cpp | 9 ++++++++- src/SimpleHandlers.cpp | 5 ++++- src/main.cpp | 23 +++++++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Response.cpp b/src/Response.cpp index 050a537..d7006c9 100644 --- a/src/Response.cpp +++ b/src/Response.cpp @@ -10,7 +10,14 @@ Response::json Response::simple_response(std::string const &text, std::string co Response::json Response::create_annotation(Reply::AnnotationType annotationType, std::string const &extra) { json annotation(crow::json::type::Object); annotation["type"] = Reply::GetStringAnnotationType(annotationType); - annotation["extra"] = extra; + annotation["extra"] = create_text(extra); + return annotation; +} + +Response::json Response::create_annotation(Reply::AnnotationType annotationType, std::vector &&extra) { + json annotation(crow::json::type::Object); + annotation["type"] = Reply::GetStringAnnotationType(annotationType); + annotation["extra"] = std::move(extra); return annotation; } diff --git a/src/SimpleHandlers.cpp b/src/SimpleHandlers.cpp index 033da53..c9d0fcf 100644 --- a/src/SimpleHandlers.cpp +++ b/src/SimpleHandlers.cpp @@ -40,7 +40,10 @@ Handler::json Handler::helpHandler(std::string const &arguments, std::string con reply_vec.emplace_back(create_text("- ")); reply_vec.emplace_back(create_text(itor.first, std::move(commandAnnotations))); - reply_vec.emplace_back(create_text(" " + itor.second.description + "\n")); + while (!itor.second.description->empty()) { + reply_vec.emplace_back(std::move(itor.second.description->back())); + itor.second.description->pop(); + } } reply_vec.emplace_back(create_text( diff --git a/src/main.cpp b/src/main.cpp index 72fd9a0..59fd6a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,10 @@ +#include +#include +#include #include -#include #include #include "crow.h" -#include "sqdb.hpp" #include "Handler.hpp" #include "Response.hpp" @@ -18,17 +19,23 @@ int main() { crow::SimpleApp app; + auto createPlainDescriptionFromText = [] (std::string const &text) -> std::queue* { + auto reply_queue = new std::queue; + reply_queue->emplace(Response::create_text(text)); + return reply_queue; + }; + // command --> handler std::unordered_map commands{ - {"wiki", {.func = Handler::wikiHandler, .description = "Send you to wikipedia"}}, - {"stop", {.func = Handler::stopHandler, .description = "Stops the bot", .payload = &app}}, - {"mensa", {.func = Handler::mensaHandler, .description = "{adlershof, nord, sued} Shows the daily menu of the mensa at various places."}}, - {"klinger", {.func = Handler::klingerHandler, .description = "Greats in french. Bonjour!"}}, - {"relation", {.func = Handler::relationShipHandler, .description = "[name1] [name2] Shows the result of an odd astrological religious pseudo-algorithm, based on the fact how much blessing a relationship receives by the glorious N."}}, + {"wiki", {.func = Handler::wikiHandler, .description = createPlainDescriptionFromText("Sends you to Wikipedia!")}}, + {"stop", {.func = Handler::stopHandler, .description = createPlainDescriptionFromText("Stops the bot"), .payload = &app}}, + {"mensa", {.func = Handler::mensaHandler, .description = createPlainDescriptionFromText("{adlershof, nord, sued} Shows the daily menu of the mensa at various places.")}}, + {"klinger", {.func = Handler::klingerHandler, .description = createPlainDescriptionFromText("Greats in french. Bonjour!")}}, + {"relation", {.func = Handler::relationShipHandler, .description = createPlainDescriptionFromText("[name1] [name2] Shows the result of an odd astrological religious pseudo-algorithm, based on the fact how much blessing a relationship receives by the glorious N.")}}, }; commands.insert({"help", - {.func = Handler::helpHandler, .description = "This is my holy manual.", .payload = &commands}}); + {.func = Handler::helpHandler, .description = createPlainDescriptionFromText("This is my holy manual."), .payload = &commands}}); CROW_ROUTE(app, "/") .methods("POST"_method) -- cgit v1.2.3-54-g00ecf