diff options
author | Benji Dial <benji@benjidial.net> | 2024-06-18 15:11:02 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-06-18 15:11:02 -0400 |
commit | d70bd2d83d68f6d51606b2101c318f6f0ff89c85 (patch) | |
tree | 5f5e7a9943af06df2fd21bcaaeab603d470505bf /source.cpp | |
parent | 5224e17a9ef3bbd6c9c3196d841e2acc66a52321 (diff) | |
download | bracket-bot-d70bd2d83d68f6d51606b2101c318f6f0ff89c85.tar.gz |
when poll gets delayed, shorten the time so it closes before midnightv2.x
Diffstat (limited to 'source.cpp')
-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 = {}; |