diff --git a/README.md b/README.md
index 924ec79..d97b4c5 100644
--- a/README.md
+++ b/README.md
@@ -13,9 +13,11 @@ Users vote by adding the matching emoji to the poll (i.e. if the first choice ha
## Version 2.0
- Changed voting format to reactions (instead of '!poll vote')
+### Version 2.0.1
+ - Allows every room to have unique poll
+
## Wish List
- Add user configuration to only allow certain users to create polls
- Add auto-timing ability
-- Add ability to run multiple polls at once
- Make emojis configurable
- Add placeholder emojis on each poll (to let users just click one)
diff --git a/maubot.yaml b/maubot.yaml
index 27920ef..5b1f0f7 100644
--- a/maubot.yaml
+++ b/maubot.yaml
@@ -9,7 +9,7 @@ maubot: 0.1.0
id: casavant.tom.poll
# A PEP 440 compliant version string.
-version: 2.0.0
+version: 2.0.1
# The SPDX license identifier for the plugin. https://spdx.org/licenses/
# Optional, assumes all rights reserved if omitted.
diff --git a/poll.py b/poll.py
index 114dd0c..023ceec 100644
--- a/poll.py
+++ b/poll.py
@@ -57,7 +57,7 @@ def close_poll(self):
class PollPlugin(Plugin):
- currentPoll = Poll("None", ["None"])
+ currentPolls = {}
@command.new("poll", help="Make a poll")
async def poll(self) -> None:
@@ -81,30 +81,36 @@ async def handler(self, evt: MessageEvent, poll_setup: str) -> None:
if len(choices) <= 1:
response = "You need to enter at least 2 choices."
else:
- self.currentPoll = Poll(question, choices)
+ self.currentPolls[evt.room_id] = Poll(question, choices)
# Show users active poll
choice_list = "
".join(
- [f"{self.currentPoll.emojis[i]} - {choice}" for i, choice in enumerate(choices)]
+ [f"{self.currentPolls[evt.room_id].emojis[i]} - {choice}" for i, choice in enumerate(choices)]
)
response = f"{question}
{choice_list}"
- self.currentPoll.event_id = await evt.reply(response, allow_html=True)
+ self.currentPolls[evt.room_id].event_id = await evt.reply(response, allow_html=True)
@poll.subcommand("results", help="Prints out the current results of the poll")
async def handler(self, evt: MessageEvent) -> None:
await evt.mark_read()
- await evt.reply(self.currentPoll.get_results(), allow_html=True)
+ if evt.room_id in self.currentPolls:
+ await evt.reply(self.currentPolls[evt.room_id].get_results(), allow_html=True)
+ else:
+ await evt.reply("There is no active poll in this room", allow_html=True)
@poll.subcommand("close", help="Ends the poll")
async def handler(self, evt: MessageEvent) -> None:
await evt.mark_read()
- self.currentPoll.close_poll()
- await evt.reply("This poll is now over. Type !poll results to see the results.")
+ if evt.room_id in self.currentPolls:
+ self.currentPolls[evt.room_id].close_poll()
+ await evt.reply("This poll is now over. Type !poll results to see the results.")
+ else:
+ await evt.reply("There is no active poll in this room")
@command.passive(regex=r"(?:("+'|'.join(REACTIONS) + r")[\U0001F3FB-\U0001F3FF]?)",
field=lambda evt: evt.content.relates_to.key,
event_type=EventType.REACTION, msgtypes=None)
async def get_react_vote(self, evt: ReactionEvent, _: Tuple[str]) -> None:
- if (evt.content.relates_to.event_id == self.currentPoll.event_id): # Is this on the correct message?
- if not self.currentPoll.hasVoted(evt.sender): # has the user already voted?
- if (evt.content.relates_to.key in self.currentPoll.emojis): # Is this a possible choice?
- self.currentPoll.vote(self.currentPoll.emojis.index(evt.content.relates_to.key), evt.sender) # Add vote/sender to poll
+ if (evt.content.relates_to.event_id == self.currentPolls[evt.room_id].event_id): # Is this on the correct message?
+ if not self.currentPolls[evt.room_id].hasVoted(evt.sender): # has the user already voted?
+ if (evt.content.relates_to.key in self.currentPolls[evt.room_id].emojis): # Is this a possible choice?
+ self.currentPolls[evt.room_id].vote(self.currentPolls[evt.room_id].emojis.index(evt.content.relates_to.key), evt.sender) # Add vote/sender to poll