]> git.aero2k.de Git - urlbot-v3.git/commitdiff
poll: fix max time, add ending time in status
authorThorsten <mail@aero2k.de>
Sun, 8 Sep 2024 06:27:22 +0000 (08:27 +0200)
committerThorsten <mail@aero2k.de>
Sun, 8 Sep 2024 06:31:07 +0000 (08:31 +0200)
src/distbot/plugins/votepoll.py

index 4fd987badfa0cf2891a22962c7d9c3fbe5f22df8..e6941ec5211bb99190443ffcea8ade19f5640dc0 100644 (file)
@@ -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)