From 60ea2b8572e54c4aecab2ecff9ff53426e4674d3 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 9 May 2018 09:07:33 +0200 Subject: [PATCH] formatting --- BeezleBot/BeezleBot.cpp | 58 +++++++++++++++++++++-------------------- BeezleBot/settings.cpp | 58 +++++++++++++++++++++++------------------ BeezleBot/settings.h | 3 +-- libdokuwiki | 2 +- 4 files changed, 65 insertions(+), 56 deletions(-) diff --git a/BeezleBot/BeezleBot.cpp b/BeezleBot/BeezleBot.cpp index 352f90b..6dab1de 100644 --- a/BeezleBot/BeezleBot.cpp +++ b/BeezleBot/BeezleBot.cpp @@ -11,47 +11,47 @@ int main(int argc, char **argv) { Settings settings(argc, argv); - DokuWiki wiki(settings.wikiUrl + "/lib/exe/xmlrpc.php", - settings.wikiUser, settings.wikiPassword); + DokuWiki wiki(settings.wikiUrl + "/lib/exe/xmlrpc.php", + settings.wikiUser, settings.wikiPassword); tgbot::LongPollBot bot(settings.telegramToken); - bot.callback(tgbot::utils::whenStarts, []( - const tgbot::types::Message message, - const tgbot::methods::Api &api, - const std::vector args) - { - api.sendMessage(std::to_string(message.chat.id), "pong"); - }, "/ping"); + bot.callback(tgbot::utils::whenStarts, + [](const tgbot::types::Message message, + const tgbot::methods::Api &api, + const std::vector args) { + api.sendMessage(std::to_string(message.chat.id), "pong"); + }, + "/ping"); - bot.callback(tgbot::utils::whenStarts, []( - const tgbot::types::Message message, - const tgbot::methods::Api &api, - const std::vector args) - { - api.sendMessage(std::to_string(message.chat.id), + bot.callback(tgbot::utils::whenStarts, + [](const tgbot::types::Message message, + const tgbot::methods::Api &api, + const std::vector args) { + api.sendMessage(std::to_string(message.chat.id), "Bot commands:\n" "/ping \tsend life-sign\n" - "/help \tshow this message" - ); - }, "/help"); + "/help \tshow this message"); + }, + "/help"); bot.callback([&wiki, &settings](const tgbot::types::Message message, - const tgbot::methods::Api &api) - { + const tgbot::methods::Api &api) { if (message.text != nullptr && message.from != nullptr - && message.from->username != nullptr) + && message.from->username != nullptr) { if (settings.telegramUsers.find(*message.from->username) - == settings.telegramUsers.end()) + == settings.telegramUsers.end()) { - api.sendMessage(std::to_string(message.chat.id), "Unknown user!"); + api.sendMessage( + std::to_string(message.chat.id), "Unknown user!"); } else { std::ostringstream logMessage; - logMessage << message.from->firstName << " (" << *message.from->username << ")" - << ":\\\\ " << *message.text; + logMessage << message.from->firstName << " (" + << *message.from->username << ")" + << ":\\\\ " << *message.text; api.getLogger().info(logMessage.str()); std::ostringstream wikiMessage; @@ -61,8 +61,9 @@ int main(int argc, char **argv) wiki.appendToPage("beezletest", wikiMessage.str()); std::ostringstream pageUrl; - pageUrl << settings.wikiUrl << "/doku.php?id=" << "beezletest"; - api.sendMessage(std::to_string(message.chat.id), + pageUrl << settings.wikiUrl << "/doku.php?id=" + << "beezletest"; + api.sendMessage(std::to_string(message.chat.id), "Stored to wiki at " + pageUrl.str()); } catch (std::runtime_error &e) @@ -70,7 +71,8 @@ int main(int argc, char **argv) std::ostringstream reply; reply << "Error writing to wiki: " << e.what(); api.getLogger().error(reply.str()); - api.sendMessage(std::to_string(message.chat.id), reply.str()); + api.sendMessage( + std::to_string(message.chat.id), reply.str()); } } } diff --git a/BeezleBot/settings.cpp b/BeezleBot/settings.cpp index 0dbbdca..a95c4a5 100644 --- a/BeezleBot/settings.cpp +++ b/BeezleBot/settings.cpp @@ -13,19 +13,22 @@ Settings::Settings(int argc, char **argv) std::vector telegramUserList; po::options_description commandlineOptions("Allowed options"); - commandlineOptions.add_options() - ("help,h", "show this help message") - ("config-file,f", po::value(), "read options from config file") - ("telegram-token", po::value(&telegramToken)->required(), "Telegram bot token") - ("telegram-users", po::value(&telegramUserList)->multitoken()->required(), "allowed Telegram users") - ("wiki-url", po::value(&wikiUrl)->required(), "DokuWiki xml-rpc url") - ("wiki-username", po::value(&wikiUser)->required(), "DokuWiki xml-rpc username") - ("wiki-password", po::value(&wikiPassword)->required(), "DokuWiki xml-rpc password") - ; + commandlineOptions.add_options()("help,h", "show this help message")( + "config-file,f", po::value(), + "read options from config file")("telegram-token", + po::value(&telegramToken)->required(), + "Telegram bot token")("telegram-users", + po::value(&telegramUserList)->multitoken()->required(), + "allowed Telegram users")("wiki-url", po::value(&wikiUrl)->required(), + "DokuWiki xml-rpc url")("wiki-username", + po::value(&wikiUser)->required(), + "DokuWiki xml-rpc username")("wiki-password", + po::value(&wikiPassword)->required(), "DokuWiki xml-rpc password"); po::variables_map configuredOptions; - po::store(po::command_line_parser(argc, argv).options(commandlineOptions).run(), - configuredOptions); + po::store( + po::command_line_parser(argc, argv).options(commandlineOptions).run(), + configuredOptions); if (configuredOptions.find("help") != configuredOptions.cend()) { @@ -35,26 +38,31 @@ Settings::Settings(int argc, char **argv) if (configuredOptions.find("config-file") != configuredOptions.cend()) { - std::ifstream configFile(configuredOptions["config-file"].as()); + std::ifstream configFile( + configuredOptions["config-file"].as()); po::options_description fileOptions; - fileOptions.add_options() - ("Telegram.token", po::value(&telegramToken)) - ("Telegram.users", po::value(&telegramUserList)->multitoken()) - ("DokuWiki.url", po::value(&wikiUrl)->required()) - ("DokuWiki.username", po::value(&wikiUser)->required()) - ("DokuWiki.password", po::value(&wikiPassword)->required()) - ; + fileOptions.add_options()("Telegram.token", po::value(&telegramToken))( + "Telegram.users", po::value(&telegramUserList)->multitoken())( + "DokuWiki.url", po::value(&wikiUrl)->required())( + "DokuWiki.username", po::value(&wikiUser)->required())( + "DokuWiki.password", po::value(&wikiPassword)->required()); try { - po::store(po::parse_config_file(configFile, fileOptions), configuredOptions); + po::store(po::parse_config_file(configFile, fileOptions), + configuredOptions); - configuredOptions.insert({ "telegram-token", configuredOptions["Telegram.token"] }); - configuredOptions.insert({ "telegram-users", configuredOptions["Telegram.users"] }); - configuredOptions.insert({ "wiki-url", configuredOptions["DokuWiki.url"] }); - configuredOptions.insert({ "wiki-username", configuredOptions["DokuWiki.username"] }); - configuredOptions.insert({ "wiki-password", configuredOptions["DokuWiki.password"] }); + configuredOptions.insert( + {"telegram-token", configuredOptions["Telegram.token"]}); + configuredOptions.insert( + {"telegram-users", configuredOptions["Telegram.users"]}); + configuredOptions.insert( + {"wiki-url", configuredOptions["DokuWiki.url"]}); + configuredOptions.insert( + {"wiki-username", configuredOptions["DokuWiki.username"]}); + configuredOptions.insert( + {"wiki-password", configuredOptions["DokuWiki.password"]}); } catch (po::unknown_option &e) { diff --git a/BeezleBot/settings.h b/BeezleBot/settings.h index cf95a98..d8a142f 100644 --- a/BeezleBot/settings.h +++ b/BeezleBot/settings.h @@ -12,6 +12,5 @@ struct Settings std::string wikiUser; std::string wikiPassword; - Settings(int argc, char **argv); + Settings(int argc, char **argv); }; - diff --git a/libdokuwiki b/libdokuwiki index a0ac1a7..b7c3c4c 160000 --- a/libdokuwiki +++ b/libdokuwiki @@ -1 +1 @@ -Subproject commit a0ac1a79754aab02d66a2839e5405ec2161c29e6 +Subproject commit b7c3c4c0426708e0547079f697ec92046b6a9202