diff options
-rw-r--r-- | source.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -245,6 +245,11 @@ void process_all_pending() { } } +int seconds_to_midnight() { + int seconds = (post_time_utc - time(0)) % 86400; + return seconds < 0 ? seconds + 86400 : seconds; +} + void post_poll(std::string e1, std::string e2, int poll_no) { nlohmann::json body = { { "poll", { @@ -252,7 +257,7 @@ void post_poll(std::string e1, std::string e2, int poll_no) { { "answers", { { { "poll_media", { { "text", e1 } } } }, { { "poll_media", { { "text", e2 } } } } } }, - { "duration", 23 } } } }; + { "duration", seconds_to_midnight() / 3600 } } } }; std::string msg_id = api("/channels/" + channel_id + "/messages", true, body.dump())["id"]; @@ -278,13 +283,6 @@ void send_message(std::string str) { api("/channels/" + channel_id + "/messages", true, body.dump()); } -void sleep_until_midnight() { - sleep(2); - long timestamp = time(0); - int time = (post_time_utc - timestamp) % 86400; - sleep(time < 0 ? time + 86400 : time); -} - int main() { prng.seed(time(0)); @@ -339,7 +337,9 @@ int main() { load_left_for_round(); while (true) { - sleep_until_midnight(); + sleep(seconds_to_midnight()); + sleep(2); + process_all_pending(); std::optional<std::string> advanced = {}; |