diff options
| author | 2019-06-17 17:54:41 +0100 | |
|---|---|---|
| committer | 2019-06-17 17:54:41 +0100 | |
| commit | 966515bd24bbb8fdaac7d2e5943c9e21c28caa05 (patch) | |
| tree | dd1d24a5edfcb389123010dd5d44d4f0bcf80491 /modules/vote.py | |
| parent | Support multiple concurrent votes (diff) | |
| signature | ||
Make sure new random ids are unique
Diffstat (limited to 'modules/vote.py')
| -rw-r--r-- | modules/vote.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/modules/vote.py b/modules/vote.py index bdb44b72..22e2aa91 100644 --- a/modules/vote.py +++ b/modules/vote.py @@ -9,8 +9,11 @@ class Module(ModuleManager.BaseModule): def _set_vote(self, channel, vote_id, vote): channel.set_setting("vote-%s" % vote_id, vote) - def _random_id(self): - return binascii.hexlify(os.urandom(4)).decode("ascii") + def _random_id(self, channel): + while True: + vote_id = binascii.hexlify(os.urandom(4)).decode("ascii") + if self._get_vote(channel, vote_id) == None: + return vote_id def _close_vote(self, channel, vote_id): vote = self._get_vote(channel, vote_id) @@ -21,7 +24,7 @@ class Module(ModuleManager.BaseModule): return False def _start_vote(self, channel, description): - vote_id = self._random_id() + vote_id = self._random_id(channel) vote = {"description": description, "options": {"yes": [], "no": []}, "electorate": [], "open": True, "id": vote_id} self._set_vote(channel, vote_id, vote) |
