From b5e66e3aa9c468660cb4f3d6ab0e224c97d23723 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Fri, 28 Aug 2020 21:00:23 +0200 Subject: add (rudimentary, non session based) pin veryfication for stop command --- src/main.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 8a8e4ba..948bc1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,40 +25,41 @@ int main() { }; // command --> handler - std::vector commands; - commands.emplace_back( + std::vector regular_commands; + regular_commands.emplace_back( Handler::CommandHandler{"wiki", Handler::wikiHandler, [createPlainDescriptionFromText]() { return createPlainDescriptionFromText("Sends you to Wikipedia!"); }}); - commands.emplace_back( + regular_commands.emplace_back( Handler::CommandHandler{"stop", Handler::stopHandler, [createPlainDescriptionFromText]() { return createPlainDescriptionFromText("Stops the bot"); }, &app}); - commands.emplace_back( + regular_commands.emplace_back( Handler::CommandHandler{"mensa", Handler::mensaHandler, [createPlainDescriptionFromText]() { return createPlainDescriptionFromText( "{adlershof, nord, sued} Shows the daily menu of the mensa at various places."); }}); - commands.emplace_back( + regular_commands.emplace_back( Handler::CommandHandler{"klinger", Handler::klingerHandler, [createPlainDescriptionFromText]() { return createPlainDescriptionFromText("Greats in french. Bonjour!"); }}); - commands.emplace_back( + regular_commands.emplace_back( Handler::CommandHandler{"say", Handler::sayHandler, [createPlainDescriptionFromText]() { return createPlainDescriptionFromText("Say something!"); }}); - commands.emplace_back( + regular_commands.emplace_back( Handler::CommandHandler{"relation", Handler::relationShipHandler, [createPlainDescriptionFromText]() { return 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.emplace_back(Handler::CommandHandler{"help", Handler::helpHandler, [createPlainDescriptionFromText]() { - return createPlainDescriptionFromText("This is my holy manual."); - }, &commands}); + regular_commands.emplace_back( + Handler::CommandHandler{"help", Handler::helpHandler, [createPlainDescriptionFromText]() { + return createPlainDescriptionFromText("This is my holy manual."); + }, ®ular_commands}); CROW_ROUTE(app, "/") .methods("POST"_method) - ([&commands](crow::request const &request) { + ([®ular_commands](crow::request const &request) { auto data = crow::json::load(request.body); if (!data) @@ -73,12 +74,13 @@ int main() { std::string session = (data.count("session") ? data["session"].s() : std::string("null")); auto itor = std::find_if( - commands.begin(), - commands.end(), + regular_commands.begin(), + regular_commands.end(), [command](Handler::CommandHandler const &handler) { return handler.command == command; }); - if (itor != commands.end()) { + + if (itor != regular_commands.end()) { return crow::response{itor->exec(arguments, session)}; } -- cgit v1.2.3-54-g00ecf