diff options
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | 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) | |||
3 | 3 | ||
4 | find_package(PkgConfig) | 4 | find_package(PkgConfig) |
5 | pkg_check_modules(yaml-cpp yaml-cpp REQUIRED) | 5 | pkg_check_modules(yaml-cpp yaml-cpp REQUIRED) |
6 | pkg_check_modules(mastodonpp mastodonpp REQUIRED) | ||
6 | 7 | ||
7 | add_subdirectory(vendor/libtwittercpp) | ||
8 | add_subdirectory(vendor/verbly) | 8 | add_subdirectory(vendor/verbly) |
9 | 9 | ||
10 | include_directories( | 10 | include_directories( |
11 | vendor/verbly/lib | 11 | vendor/verbly/lib |
12 | vendor/libtwittercpp/src | 12 | ${mastodonpp_INCLUDE_DIRS} |
13 | ${yaml-cpp_INCLUDE_DIRS}) | 13 | ${yaml-cpp_INCLUDE_DIRS}) |
14 | 14 | ||
15 | link_directories( | ||
16 | ${mastodonpp_LIBRARY_DIRS} | ||
17 | ${yaml-cpp_LIBRARY_DIRS}) | ||
18 | |||
15 | add_executable(wordplay wordplay.cpp) | 19 | add_executable(wordplay wordplay.cpp) |
16 | set_property(TARGET wordplay PROPERTY CXX_STANDARD 11) | 20 | set_property(TARGET wordplay PROPERTY CXX_STANDARD 17) |
17 | set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) | 21 | set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) |
18 | target_link_libraries(wordplay verbly twitter++ ${yaml-cpp_LIBRARIES}) | 22 | 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 @@ | |||
3 | #include <iostream> | 3 | #include <iostream> |
4 | #include <list> | 4 | #include <list> |
5 | #include <algorithm> | 5 | #include <algorithm> |
6 | #include <twitter.h> | 6 | #include <mastodonpp/mastodonpp.hpp> |
7 | #include <verbly.h> | 7 | #include <verbly.h> |
8 | #include <chrono> | 8 | #include <chrono> |
9 | #include <thread> | 9 | #include <thread> |
@@ -19,13 +19,10 @@ int main(int argc, char** argv) | |||
19 | std::string configfile(argv[1]); | 19 | std::string configfile(argv[1]); |
20 | YAML::Node config = YAML::LoadFile(configfile); | 20 | YAML::Node config = YAML::LoadFile(configfile); |
21 | 21 | ||
22 | twitter::auth auth; | 22 | mastodonpp::Instance instance{ |
23 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | 23 | config["mastodon_instance"].as<std::string>(), |
24 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | 24 | config["mastodon_token"].as<std::string>()}; |
25 | auth.setAccessKey(config["access_key"].as<std::string>()); | 25 | mastodonpp::Connection connection{instance}; |
26 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | ||
27 | |||
28 | twitter::client client(auth); | ||
29 | 26 | ||
30 | verbly::database database(config["verbly_datafile"].as<std::string>()); | 27 | verbly::database database(config["verbly_datafile"].as<std::string>()); |
31 | 28 | ||
@@ -75,14 +72,19 @@ int main(int argc, char** argv) | |||
75 | std::string result = action.compile(); | 72 | std::string result = action.compile(); |
76 | std::cout << result << std::endl; | 73 | std::cout << result << std::endl; |
77 | 74 | ||
78 | try | 75 | const mastodonpp::parametermap parameters{{"status", result}}; |
79 | { | 76 | auto answer{connection.post(mastodonpp::API::v1::statuses, parameters)}; |
80 | client.updateStatus(result); | 77 | if (!answer) |
81 | |||
82 | std::cout << "Tweeted!" << std::endl; | ||
83 | } catch (const twitter::twitter_error& e) | ||
84 | { | 78 | { |
85 | std::cout << "Twitter error: " << e.what() << std::endl; | 79 | if (answer.curl_error_code == 0) |
80 | { | ||
81 | std::cout << "HTTP status: " << answer.http_status << std::endl; | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | std::cout << "libcurl error " << std::to_string(answer.curl_error_code) | ||
86 | << ": " << answer.error_message << std::endl; | ||
87 | } | ||
86 | } | 88 | } |
87 | 89 | ||
88 | std::cout << "Waiting..." << std::endl; | 90 | std::cout << "Waiting..." << std::endl; |