diff --git a/CMakeLists.txt b/CMakeLists.txt index 488c38b..f640222 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastobotmon - VERSION 0.0.3 + VERSION 0.1.0 LANGUAGES CXX ) diff --git a/README.md b/README.md index d425364..5a4d38a 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,11 @@ If you use a debug build, you get more verbose error messages. # TODO * Version 0.1.0 - * [ ] Cron mode + * [x] Cron mode * [x] Config file - * [ ] Alert if account seems inactive + * [x] Alert if account seems inactive * Version 0.2.0 + * [ ] Allow to add accounts later * [ ] Write mentions to file * Version 0.3.0 * [ ] Write statistics to file diff --git a/src/mastobotmon.cpp b/src/mastobotmon.cpp index eeaa06d..9f3a8a2 100644 --- a/src/mastobotmon.cpp +++ b/src/mastobotmon.cpp @@ -18,6 +18,10 @@ #include #include #include +#include +#include +#include +#include // get_time #include #include "version.hpp" #include "mastobotmon.hpp" @@ -26,6 +30,7 @@ using std::cout; using std::cerr; using std::cin; using std::string; +using std::uint16_t; int main(int argc, char *argv[]) { @@ -69,8 +74,21 @@ int main(int argc, char *argv[]) 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"; + const string acct = json[0]["account"]["acct"].GetString(); + + std::istringstream isslast(json[0]["created_at"].GetString()); + struct std::tm tm = {0}; + isslast >> std::get_time(&tm, "%Y-%m-%dT%T"); + std::time_t time = mktime(&tm); + + const auto now = std::chrono::system_clock::now(); + const auto last = std::chrono::system_clock::from_time_t(time); + auto elapsed = std::chrono::duration_cast(now - last); + + if (elapsed.count() > acc.get_minutes()) + { + cout << "ALERT: " << acct << " is inactive since " << elapsed.count() << " minutes.\n"; + } } } diff --git a/src/mastobotmon.hpp b/src/mastobotmon.hpp index 1197896..8784294 100644 --- a/src/mastobotmon.hpp +++ b/src/mastobotmon.hpp @@ -32,7 +32,8 @@ class Account : public Mastodon::API { public: explicit Account(const string &instance, const string &access_token); - void set_minutes(uint16_t minutes); + const void set_minutes(uint16_t minutes); + const uint16_t get_minutes() const; private: uint16_t _minutes; diff --git a/src/mastodon.cpp b/src/mastodon.cpp index 872e397..ec05167 100644 --- a/src/mastodon.cpp +++ b/src/mastodon.cpp @@ -34,7 +34,12 @@ Account::Account(const string &instance, const string &access_token) // } -void Account::set_minutes(uint16_t minutes) +const void Account::set_minutes(uint16_t minutes) { _minutes = minutes; } + +const uint16_t Account::get_minutes() const +{ + return _minutes; +}