diff --git a/CMakeLists.txt b/CMakeLists.txt index b3f7a67..c331ce6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ pkg_check_modules(jsoncpp REQUIRED IMPORTED_TARGET jsoncpp) find_package(mastodonpp 0.5.4 REQUIRED CONFIG) find_package(Filesystem REQUIRED) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/feiertagebot.cpp b/feiertagebot.cpp index 087313f..3b6116e 100644 --- a/feiertagebot.cpp +++ b/feiertagebot.cpp @@ -1,6 +1,7 @@ // Author: tastytea // CC-0 / Public Domain +#include #include #include #include @@ -15,8 +16,7 @@ #include #include #include -#include -#include +#include #include "xdgjson/src/xdgjson.hpp" namespace curlopts = curlpp::options; @@ -29,7 +29,7 @@ using std::chrono::system_clock; using std::chrono::hours; using std::uint_fast16_t; -const string version = "2019-04-20_2"; +const string version = "2020-05-16_1"; struct Holiday { @@ -82,38 +82,30 @@ const string get_date(const system_clock::time_point &timepoint, const string get_token(const string &instance) { - Mastodon::API masto(instance, ""); - Mastodon::return_call ret; - string client_id, client_secret, url; - string code, access_token; - ret = masto.register_app1("feiertagebot", - "urn:ietf:wg:oauth:2.0:oob", - "write:statuses", - "https://schlomp.space/tastytea/feiertagebot", - client_id, - client_secret, - url); - if (!ret) + mastodonpp::Instance server{instance, ""}; + mastodonpp::Instance::ObtainToken token{server}; + + auto answer{token.step_1("feiertagebot", + "write:statuses", + "https://schlomp.space/tastytea/feiertagebot")}; + if (!answer) { - cerr << "Error " << std::to_string(ret.error_code) << endl; + cerr << "Error " << answer.error_message << endl; return ""; } - cout << "Visit " << url << " to authorize this application.\n"; + string code; + cout << "Visit " << answer << " to authorize this application.\n"; cout << "Insert code: "; std::getline(std::cin, code); - ret = masto.register_app2(client_id, - client_secret, - "urn:ietf:wg:oauth:2.0:oob", - code, - access_token); - if (!ret) + answer = token.step_2(code); + if (!answer) { - cerr << "Error " << std::to_string(ret.error_code) << endl; + cerr << "Error " << answer.error_message << endl; return ""; } - return access_token; + return answer.body; } int main() @@ -213,16 +205,15 @@ int main() if (!output.empty()) { - Mastodon::Easy::return_entity ret; - Mastodon::Easy::API masto(instance, access_token); - masto.exceptions(true); - Mastodon::Easy::Status status; - status.content(output + "#bot"); - ret = masto.send_post(status); - if (!ret) + mastodonpp::Instance server{instance, access_token}; + mastodonpp::Connection connection{server}; + string status{output + "#bot"}; + const auto answer{connection.post(mastodonpp::API::v1::statuses, + {{"status", output}})}; + if (!answer) { - cerr << "Error " << std::to_string(ret.error_code) << endl; - return ret.error_code; + cerr << "Error " << answer.error_message << endl; + return answer.curl_error_code; } } }