From eaddb0bc633bd7411d2e3aabc45b7f2aeda6fc9d Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sun, 8 Sep 2024 13:15:12 +0200 Subject: [PATCH] poll: add prefixes --- src/distbot/plugins/votepoll.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/distbot/plugins/votepoll.py b/src/distbot/plugins/votepoll.py index 0111cf3..9768df3 100644 --- a/src/distbot/plugins/votepoll.py +++ b/src/distbot/plugins/votepoll.py @@ -84,6 +84,15 @@ class Poll: def to_json(self): return json.dumps(self, default=lambda o: o.__dict__) + def option_listing(self, with_votes=False): + lines = [] + for i, option in enumerate(self.options): + line = f" * {chr(65 + i)} - {option}" + if with_votes: + line += f": {self.get_votes(option)}" + lines.append(line) + return "\n".join(lines) + def status_report(self): # Calculate winner and format result message winner = "It's a tie!" @@ -99,8 +108,7 @@ class Poll: winner = f"**Winners:** {', '.join(winners)}" status_message = f"**Poll status:**\n" - for option in self.options: - status_message += f" * {option}: {self.get_votes(option)}\n" + status_message += self.option_listing(with_votes=True) status_message += (f"\n{winner}" if self.due() else f"\nEnding at: {self.end_date}") return status_message @@ -177,11 +185,11 @@ class VotePoll(Worker): # setup timeout to disable poll and present results bot_nick = conf_get("bot_nickname") - option_listing = "\n".join(" * {} - {}".format(chr(65 + i), option) for i, option in enumerate(options)) + poll_message = (f"**New Vote:** {sender} started a vote! " f"Vote within {vote_duration}s " f"(reply with '{bot_nick}: vote A/B/foo' within {vote_duration}s)" - f"\nOptions are:\n") + option_listing + f"\nOptions are:\n") + poll.option_listing() return Action( msg=poll_message, event=Action(time=now + vote_duration, command="nick.pollstatus", -- 2.39.2