Upgrade from mastodon-cpp to mastodonpp.
Adds dependency on C++17.
This commit is contained in:
parent
57e391d605
commit
ee8f842818
|
@ -5,7 +5,12 @@ project (soupbot
|
||||||
VERSION 0.3.2
|
VERSION 0.3.2
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall")
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
find_package(mastodonpp REQUIRED CONFIG)
|
||||||
|
|
||||||
# Write version in header
|
# Write version in header
|
||||||
configure_file (
|
configure_file (
|
||||||
|
@ -15,7 +20,7 @@ configure_file (
|
||||||
include_directories(${PROJECT_BINARY_DIR})
|
include_directories(${PROJECT_BINARY_DIR})
|
||||||
|
|
||||||
add_executable(soupbot src/soupbot.cpp)
|
add_executable(soupbot src/soupbot.cpp)
|
||||||
target_link_libraries(soupbot mastodon-cpp boost_system boost_filesystem ssl crypto)
|
target_link_libraries(soupbot mastodonpp boost_system boost_filesystem ssl crypto)
|
||||||
install(TARGETS soupbot DESTINATION ${CMAKE_INSTALL_BINDIR})
|
install(TARGETS soupbot DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
||||||
install(FILES ingredients.json
|
install(FILES ingredients.json
|
||||||
|
|
20
README.md
20
README.md
|
@ -5,10 +5,10 @@
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
* Tested OS: Linux
|
* Tested OS: Linux
|
||||||
* C++ compiler (tested: gcc 8)
|
* C++ compiler (tested: gcc 9)
|
||||||
* [cmake](https://cmake.org/) (tested: 3.9)
|
* [cmake](https://cmake.org/) (tested: 3.16)
|
||||||
* [boost](http://www.boost.org/) (tested: 1.65)
|
* [boost](http://www.boost.org/) (tested: 1.72)
|
||||||
* [mastodon-cpp](https://schlomp.space/tastytea/mastodon-cpp) (at least: 0.105.0)
|
* [mastodonpp](https://schlomp.space/tastytea/mastodonpp) (at least: 0.5.5)
|
||||||
|
|
||||||
## Get sourcecode
|
## Get sourcecode
|
||||||
|
|
||||||
|
@ -39,20 +39,10 @@ Copy `ingredients.json` to `~/.config/soupbot/ingredients.json`.
|
||||||
|
|
||||||
You will need a pre-generated authentication code.
|
You will need a pre-generated authentication code.
|
||||||
|
|
||||||
## Error codes
|
|
||||||
|
|
||||||
Same as
|
|
||||||
[mastodon-cpp](https://schlomp.space/tastytea/mastodon-cpp/src/branch/master/README.md#error-codes),
|
|
||||||
plus:
|
|
||||||
|
|
||||||
| Code | Explanation |
|
|
||||||
| --------: |:------------------------------|
|
|
||||||
| 1 | File not readable |
|
|
||||||
|
|
||||||
# Copyright
|
# Copyright
|
||||||
|
|
||||||
``` text
|
``` text
|
||||||
Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>.
|
Copyright © 2018, 2019, 2020 tastytea <tastytea@tastytea.de>.
|
||||||
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
|
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
|
||||||
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
|
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
|
||||||
and you are welcome to redistribute it under certain conditions.
|
and you are welcome to redistribute it under certain conditions.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of soupbot.
|
/* This file is part of soupbot.
|
||||||
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2018, 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,23 +14,23 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include "version.hpp"
|
||||||
#include <vector>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
|
#include <boost/property_tree/ptree.hpp>
|
||||||
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <random>
|
#include <iostream>
|
||||||
#include <chrono>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <mastodon-cpp/mastodon-cpp.hpp>
|
#include <mastodonpp/mastodonpp.hpp>
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <random>
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <string>
|
||||||
#include <boost/filesystem.hpp>
|
#include <vector>
|
||||||
#include "version.hpp"
|
|
||||||
|
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
using namespace Mastodon;
|
namespace masto = mastodonpp;
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -42,7 +42,8 @@ void read_config(pt::ptree &config, string &instance, string &access_token)
|
||||||
bool config_changed = false;
|
bool config_changed = false;
|
||||||
|
|
||||||
// Read config file, get access token
|
// Read config file, get access token
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
pt::read_json(filepath + "config.json", config);
|
pt::read_json(filepath + "config.json", config);
|
||||||
instance = config.get("instance", "");
|
instance = config.get("instance", "");
|
||||||
access_token = config.get("access_token", "");
|
access_token = config.get("access_token", "");
|
||||||
|
@ -79,9 +80,9 @@ void populate_vector(const pt::ptree &ingredients, const string &node,
|
||||||
std::vector<string> &vector)
|
std::vector<string> &vector)
|
||||||
{
|
{
|
||||||
const pt::ptree childs = ingredients.get_child(node);
|
const pt::ptree childs = ingredients.get_child(node);
|
||||||
std::transform(childs.begin(), childs.end(), std::back_inserter(vector),
|
std::transform(
|
||||||
[](const pt::ptree::value_type &value)
|
childs.begin(), childs.end(), std::back_inserter(vector),
|
||||||
{ return value.second.data(); });
|
[](const pt::ptree::value_type &value) { return value.second.data(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
string get_ingredient(std::vector<string> &vector)
|
string get_ingredient(std::vector<string> &vector)
|
||||||
|
@ -91,7 +92,8 @@ string get_ingredient(std::vector<string> &vector)
|
||||||
|
|
||||||
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
|
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
|
||||||
std::default_random_engine generator(seed);
|
std::default_random_engine generator(seed);
|
||||||
std::uniform_int_distribution<std::uint16_t> distribution(0, vector.size() - 1);
|
std::uniform_int_distribution<std::uint16_t> distribution(0, vector.size()
|
||||||
|
- 1);
|
||||||
const std::uint16_t i = distribution(generator);
|
const std::uint16_t i = distribution(generator);
|
||||||
const string ingredient = vector.at(i);
|
const string ingredient = vector.at(i);
|
||||||
|
|
||||||
|
@ -120,7 +122,8 @@ int main()
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
// most likely file not found
|
// most likely file not found
|
||||||
std::cerr << "ERROR: " << filepath << "ingredients.json not found or not readable.\n";
|
std::cerr << "ERROR: " << filepath
|
||||||
|
<< "ingredients.json not found or not readable.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,25 +174,22 @@ int main()
|
||||||
|
|
||||||
toot += ", \nand plenty oil. Salt to taste. \n\nHappy cooking! 🍲 \n\n#bot";
|
toot += ", \nand plenty oil. Salt to taste. \n\nHappy cooking! 🍲 \n\n#bot";
|
||||||
|
|
||||||
return_call ret;
|
masto::Instance server{instance, access_token};
|
||||||
API masto(instance, access_token);
|
server.set_useragent("soupbot/" + (string)global::version);
|
||||||
masto.set_useragent("soupbot/" + (string)global::version);
|
masto::Connection connection{server};
|
||||||
|
|
||||||
parameters params =
|
masto::parametermap params = {{"status", {toot}},
|
||||||
{
|
{"visibility", {"public"}}};
|
||||||
{ "status", { toot } },
|
auto ret{connection.post(masto::API::v1::statuses, params)};
|
||||||
{ "visibility", { "public" } }
|
|
||||||
};
|
|
||||||
ret = masto.post(API::v1::statuses, params);
|
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
cout << ret.answer << '\n';
|
cout << ret.body << '\n';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Error code: " << ret.error_code << '\n';
|
std::cerr << "Error code: " << ret.curl_error_code << '\n';
|
||||||
return ret.error_code;
|
return ret.curl_error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue