async def create_vote(self, action, player, passed_event): """ Called to create a new current vote. :param action: kind of vote that should be created :param player: player requesting the vote :param passed_event: method to be called when the vote is passed """ ratio = await self.setting_voting_ratio.get_value() players = self.instance.player_manager.count_players new_vote = Vote() new_vote.action = action new_vote.requester = player new_vote.votes_current = [] needed_votes = round(players * ratio) if needed_votes > players: needed_votes = players new_vote.votes_required = needed_votes new_vote.vote_added = self.vote_added new_vote.vote_removed = self.vote_removed new_vote.vote_passed = passed_event time_limit = await self.setting_voting_timeout.get_value() if time_limit > 0: new_vote.time_limit = datetime.datetime.now() + datetime.timedelta( 0, time_limit) asyncio.ensure_future(self.vote_canceller(new_vote)) asyncio.ensure_future(self.vote_reminder(new_vote)) # Set the current vote here, so the widget can access it. self.current_vote = new_vote # Display the voting widget. await self.widget.display() # Hide the widget for the vote requester, as that person always votes. await self.widget.hide(player_logins=[player.login]) return new_vote
async def create_vote(self, action, player, finished_event): ratio = await self.setting_voting_ratio.get_value() players = self.instance.player_manager.count_players new_vote = Vote() new_vote.action = action new_vote.requester = player new_vote.votes_current = [] needed_votes = round(players * ratio) if needed_votes > players: needed_votes = players new_vote.votes_required = needed_votes new_vote.vote_added = self.vote_added new_vote.vote_removed = self.vote_removed new_vote.vote_finished = finished_event asyncio.ensure_future(self.vote_reminder(new_vote)) return new_vote