From ab9fbaf04db6882871264fc95276f319c4e65994 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sun, 8 Sep 2024 08:27:22 +0200 Subject: [PATCH] poll: fix max time, add ending time in status --- src/distbot/plugins/votepoll.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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) -- 2.39.2