From: Thorsten Date: Sun, 8 Sep 2024 06:27:22 +0000 (+0200) Subject: poll: fix max time, add ending time in status X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=ab9fbaf04db6882871264fc95276f319c4e65994;p=urlbot-v3.git poll: fix max time, add ending time in status --- diff --git a/src/distbot/plugins/votepoll.py b/src/distbot/plugins/votepoll.py index 4fd987b..e6941ec 100644 --- a/src/distbot/plugins/votepoll.py +++ b/src/distbot/plugins/votepoll.py @@ -37,6 +37,10 @@ class Poll: def key(self): return self.generate_key(self.option_a, self.option_b) + @property + def end_date(self): + return datetime.fromtimestamp(self.ending_at) + def votes_a(self) -> int: return len([vote for vote in self.votes.values() if vote == self.option_a]) @@ -78,7 +82,7 @@ class Poll: status_message = (f"**Poll status:**\n" f" * {self.option_a}: {self.votes_a()}\n" f" * {self.option_b}: {self.votes_b()}" - ) + (f"\n{winner}" if self.due() else "") + ) + (f"\n{winner}" if self.due() else f"\nEnding at: {self.end_date}") return status_message @@ -141,7 +145,7 @@ class VotePoll(Worker): vote_duration = self.vote_duration if len(words) == 5: try: - vote_duration = max(30, min(60 * 60 * 3, int(words[4]))) + vote_duration = max(30, min(self.max_vote_duration, int(words[4]))) except ValueError as e: logger.exception("Failed parsing intended duration", exc_info=e) # setup new poll @@ -152,8 +156,8 @@ class VotePoll(Worker): else: prior_poll = self.get_poll(poll.key) if prior_poll and prior_poll.votes: - date = datetime.fromtimestamp(prior_poll.ending_at) - return Action(msg=f"This was already decided at {date}: {prior_poll.status_report()}") + + return Action(msg=f"This was already decided at {prior_poll.end_date}: {prior_poll.status_report()}") # enable poll self.start_poll(poll)