diff --git a/CMakeLists.txt b/CMakeLists.txt index b9b1d19..488c38b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastobotmon - VERSION 0.0.2 + VERSION 0.0.3 LANGUAGES CXX ) diff --git a/README.md b/README.md index 5920bb9..fc0190b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Call mastobotmon from cron. * Version 0.1.0 * [ ] Cron mode - * [ ] Config file + * [x] Config file * [ ] Alert if account seems inactive * Version 0.2.0 * [ ] Write mentions to file diff --git a/src/config.cpp b/src/config.cpp index 0a676b5..0d4e772 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -128,6 +128,7 @@ const string get_access_token(const string &account) { const string instance = account.substr(account.find('@') + 1); Account acc(instance, ""); + acc.set_useragent("mastobotmon/" + string(global::version)); uint16_t ret; string client_id; string client_secret; diff --git a/src/mastobotmon.cpp b/src/mastobotmon.cpp index 0b6c616..eeaa06d 100644 --- a/src/mastobotmon.cpp +++ b/src/mastobotmon.cpp @@ -39,31 +39,45 @@ int main(int argc, char *argv[]) for (const auto &member : document["accounts"].GetObject()) { - // Construct an Account object for every account + // Construct an Account object for every account and store it in a vector string instance = member.name.GetString(); instance = instance.substr(instance.find('@') + 1); - Account acc(instance, member.value["access_token"].GetString()); - acc.set_minutes(member.value["minutes"].GetUint()); - accounts.push_back(acc); + + Account *acc = new Account(instance, member.value["access_token"].GetString()); + acc->set_useragent("mastobotmon/" + string(global::version)); + acc->set_minutes(member.value["minutes"].GetUint()); + accounts.push_back(*acc); } - cout << "DEBUG\n"; if (document["mode"] == "cron") { - cout << "DEBUG\n"; for (Account &acc : accounts) { - cout << "DEBUG\n"; std::string answer; - // std::string id; + uint16_t ret = acc.get(Mastodon::API::v1::accounts_verify_credentials, answer); + if (ret == 0) + { + rapidjson::Document json; + json.Parse(answer.c_str()); + const string id = json["id"].GetString(); - // Account::parametermap parameters( - // { - // { "limit", { "1" } } - // }); - // cout << acc.get(Mastodon::API::v1::statuses, id, parameters, answer); - cout << acc.get(Mastodon::API::v1::accounts_verify_credentials, answer); - cout << answer << '\n'; + Account::parametermap parameters( + { + { "limit", { "1" } } + }); + ret = acc.get(Mastodon::API::v1::accounts_id_statuses, id, parameters, answer); + if (ret == 0) + { + json.Parse(answer.c_str()); + cout << "The last toot of " << json[0]["account"]["acct"].GetString() + << " was at " << json[0]["created_at"].GetString() << ".\n"; + } + } + + if (ret != 0) + { + cerr << "Error: " << ret << '\n'; + } } } diff --git a/src/mastobotmon.hpp b/src/mastobotmon.hpp index 0ff39ad..1197896 100644 --- a/src/mastobotmon.hpp +++ b/src/mastobotmon.hpp @@ -36,7 +36,6 @@ public: private: uint16_t _minutes; - string _access_token; }; #endif // mastobotmon_HPP diff --git a/src/mastodon.cpp b/src/mastodon.cpp index c9131b0..872e397 100644 --- a/src/mastodon.cpp +++ b/src/mastodon.cpp @@ -30,7 +30,6 @@ using std::uint16_t; Account::Account(const string &instance, const string &access_token) : API(instance, access_token) , _minutes(0) -, _access_token("") { // }