示例#1
0
 def messages(self, gamedb: Database) -> List[SMSEventMessage]:
     player_messages = []
     players = gamedb.stream_players(active_player_predicate_value=True)
     # TODO(brandon): parallelize
     # NOTE(brandon) this is going to be problematic at scale. we're sending personalized links to
     # every player in the game, which costs 1 API call / player within Twilio. If we can make these links
     # standard then a single Notify API call can address all users in a single game. Non-critical for MVP.
     for player in players:
         player_messages.append(
             SMSEventMessage(
                 content=messages.NOTIFY_TRIBAL_CHALLENGE_EVENT_MSG_FMT.
                 format(
                     header=messages.game_sms_header(gamedb=gamedb),
                     challenge=self.challenge.name,
                     # TODO(brandon) refactor into common routes location
                     link=
                     "{hostname}/challenge-submission/{player_id}/{game_id}/{challenge_id}"
                     .format(hostname=messages.VIR_US_HOSTNAME,
                             game_id=self.game_id,
                             player_id=player.id,
                             challenge_id=self.challenge.id),
                     time=self.game_options.game_schedule.
                     localized_time_string(self.game_options.game_schedule.
                                           daily_challenge_end_time)),
                 recipient_phone_numbers=[player.phone_number]))
     return player_messages
示例#2
0
    def _run_finalist_tribe_council(self, finalists: List[Player],
                                    gamedb: Database,
                                    engine: Engine) -> Player:
        gamedb.clear_votes()
        self._wait_for_tribal_council_start_time()

        engine.add_event(
            events.NotifyFinalTribalCouncilEvent(game_id=self._game_id,
                                                 game_options=self._options,
                                                 finalists=finalists))
        self._wait_for_tribal_council_end_time()

        # count votes
        player_votes = gamedb.count_votes(is_for_win=True)
        max_votes = 0
        winner = None

        for player_id, votes in player_votes.items():
            if votes > max_votes:
                max_votes = votes
                winner = gamedb.player_from_id(id=player_id)

        for player in gamedb.stream_players(
                active_player_predicate_value=True):
            if player.id != winner.id:
                gamedb.deactivate_player(player=player)

        # announce winner
        engine.add_event(
            events.NotifyWinnerAnnouncementEvent(game_id=self._game_id,
                                                 game_options=self._options,
                                                 winner=winner))
        return winner
示例#3
0
 def messages(self, gamedb: Database) -> List[SMSEventMessage]:
     return [
         SMSEventMessage(
             content=messages.NOTIFY_TRIBAL_COUNCIL_COMPLETION_EVENT_MSG_FMT.format(
                 header=messages.VIR_US_SMS_HEADER,
                 date=self.game_options.game_schedule.tomorrow_localized_string,
                 time=self.game_options.game_schedule.localized_time_string(
                     self.game_options.game_schedule.daily_challenge_start_time
                 )
             ),
             recipient_phone_numbers=[p.phone_number for p in gamedb.stream_players(
                 active_player_predicate_value=True)]
         )
     ]
示例#4
0
 def messages(self, gamedb: Database) -> List[SMSEventMessage]:
     options_map = messages.players_as_formatted_options_map(
         players=self.finalists)
     # TODO(brandon): this is slow and expensive, but it should work.
     for player in gamedb.stream_players():
         gamedb.ballot(player_id=player.id,
                       challenge_id=None,
                       options=options_map.options,
                       is_for_win=True)
     return [
         SMSEventMessage(
             content=messages.NOTIFY_FINAL_TRIBAL_COUNCIL_EVENT_MSG_FMT.
             format(
                 header=messages.game_sms_header(gamedb=gamedb),
                 players=len(self.finalists),
                 game=gamedb.game_from_id(id=self.game_id).hashtag,
                 time=self.game_options.game_schedule.localized_time_string(
                     self.game_options.game_schedule.
                     daily_tribal_council_end_time),
                 options=options_map.formatted_string),
             recipient_phone_numbers=[
                 p.phone_number for p in gamedb.stream_players()
             ])
     ]
示例#5
0
 def messages(self, gamedb: Database) -> List[SMSEventMessage]:
     return [
         SMSEventMessage(
             content=messages.NOTIFY_FINAL_TRIBAL_COUNCIL_EVENT_MSG_FMT.format(
                 header=messages.VIR_US_HOSTNAME,
                 players=len(self.finalists),
                 game=gamedb.game_from_id(id=self.game_id).hashtag,
                 time=self.game_options.game_schedule.localized_time_string(
                     self.game_options.game_schedule.daily_tribal_council_end_time
                 ),
                 options=messages.players_as_formatted_options_list(
                     players=self.finalists)
             ),
             recipient_phone_numbers=[p.phone_number for p in gamedb.stream_players(
                 active_player_predicate_value=True)]
         )
     ]
示例#6
0
 def messages(self, gamedb: Database) -> List[SMSEventMessage]:
     game_hashtag = gamedb.game_from_id(id=self.game_id).hashtag
     return [
         SMSEventMessage(
             content=messages.
             NOTIFY_WINNER_ANNOUNCEMENT_EVENT_WINNER_MSG_FMT.format(
                 header=messages.game_sms_header(gamedb=gamedb),
                 game=game_hashtag),
             recipient_phone_numbers=[self.winner.phone_number]),
         SMSEventMessage(
             content=messages.
             NOTIFY_WINNER_ANNOUNCEMENT_EVENT_GENERAL_MSG_FMT.format(
                 header=messages.game_sms_header(gamedb=gamedb),
                 player=messages.format_tiktok_username(self.winner.tiktok),
                 game=game_hashtag),
             recipient_phone_numbers=[
                 p.phone_number for p in gamedb.stream_players(
                     active_player_predicate_value=False)
             ])
     ]