Switched from mastodon-cpp to mastodonpp.

This commit is contained in:
tastytea 2020-05-16 17:38:10 +02:00
parent 3e5a7def80
commit 73aa20a193
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 26 additions and 35 deletions

View File

@ -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)

View File

@ -1,6 +1,7 @@
// Author: tastytea <tastytea@tastytea.de>
// CC-0 / Public Domain
#include <mastodonpp/instance.hpp>
#include <string>
#include <exception>
#include <iostream>
@ -15,8 +16,7 @@
#include <curlpp/Exception.hpp>
#include <curlpp/Infos.hpp>
#include <json/json.h>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/entities/status.hpp>
#include <mastodonpp/mastodonpp.hpp>
#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<Mastodon::Easy::Status> 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;
}
}
}