From c51eb502c568ea2d84933b8e2445e98c81307671 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 15 Nov 2022 11:41:38 -0500 Subject: Bot now posts to Mastodon instead of Twitter You need to install mastodonpp on your server. --- CMakeLists.txt | 12 ++++++++---- wordplay.cpp | 32 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe7fd64..3f11278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,16 +3,20 @@ project (wordplay) find_package(PkgConfig) pkg_check_modules(yaml-cpp yaml-cpp REQUIRED) +pkg_check_modules(mastodonpp mastodonpp REQUIRED) -add_subdirectory(vendor/libtwittercpp) add_subdirectory(vendor/verbly) include_directories( vendor/verbly/lib - vendor/libtwittercpp/src + ${mastodonpp_INCLUDE_DIRS} ${yaml-cpp_INCLUDE_DIRS}) +link_directories( + ${mastodonpp_LIBRARY_DIRS} + ${yaml-cpp_LIBRARY_DIRS}) + add_executable(wordplay wordplay.cpp) -set_property(TARGET wordplay PROPERTY CXX_STANDARD 11) +set_property(TARGET wordplay PROPERTY CXX_STANDARD 17) set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) -target_link_libraries(wordplay verbly twitter++ ${yaml-cpp_LIBRARIES}) +target_link_libraries(wordplay verbly ${mastodonpp_LIBRARIES} ${yaml-cpp_LIBRARIES}) diff --git a/wordplay.cpp b/wordplay.cpp index 5b60a4f..d5051e6 100644 --- a/wordplay.cpp +++ b/wordplay.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -19,13 +19,10 @@ int main(int argc, char** argv) std::string configfile(argv[1]); YAML::Node config = YAML::LoadFile(configfile); - twitter::auth auth; - auth.setConsumerKey(config["consumer_key"].as()); - auth.setConsumerSecret(config["consumer_secret"].as()); - auth.setAccessKey(config["access_key"].as()); - auth.setAccessSecret(config["access_secret"].as()); - - twitter::client client(auth); + mastodonpp::Instance instance{ + config["mastodon_instance"].as(), + config["mastodon_token"].as()}; + mastodonpp::Connection connection{instance}; verbly::database database(config["verbly_datafile"].as()); @@ -75,14 +72,19 @@ int main(int argc, char** argv) std::string result = action.compile(); std::cout << result << std::endl; - try - { - client.updateStatus(result); - - std::cout << "Tweeted!" << std::endl; - } catch (const twitter::twitter_error& e) + const mastodonpp::parametermap parameters{{"status", result}}; + auto answer{connection.post(mastodonpp::API::v1::statuses, parameters)}; + if (!answer) { - std::cout << "Twitter error: " << e.what() << std::endl; + if (answer.curl_error_code == 0) + { + std::cout << "HTTP status: " << answer.http_status << std::endl; + } + else + { + std::cout << "libcurl error " << std::to_string(answer.curl_error_code) + << ": " << answer.error_message << std::endl; + } } std::cout << "Waiting..." << std::endl; -- cgit 1.4.1