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!"
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
# 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",