def messages(self, gamedb: Database) -> List[SMSEventMessage]: player_messages = [] losing_teams = gamedb.stream_teams(from_tribe=self.losing_tribe) winning_teams = gamedb.stream_teams(from_tribe=self.winning_tribe) for team in losing_teams: losing_players = [] # TODO(brandon): optimize this. for player in gamedb.list_players(from_team=team): losing_players.append(player) options_map = messages.players_as_formatted_options_map( players=losing_players) for player in losing_players: gamedb.ballot(player_id=player.id, options=options_map.options, challenge_id=None) # NOTE: UX isn't perfect here because we'll show the player's own name # as an option to vote out. For MVP this helps with scale because the alternative # requires sending a different message to every player (as opposed to every team) # which is about a 5x cost increase for SMS. player_messages.append( SMSEventMessage( content=messages. NOTIFY_MULTI_TRIBE_COUNCIL_EVENT_LOSING_MSG_FMT.format( header=messages.game_sms_header(gamedb=gamedb), tribe=self.losing_tribe.name, 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 losing_players ])) winning_player_phone_numbers = [] for team in winning_teams: winning_players = gamedb.list_players(from_team=team) winning_player_phone_numbers.extend( [p.phone_number for p in winning_players]) player_messages.append( SMSEventMessage( content=messages. NOTIFY_MULTI_TRIBE_COUNCIL_EVENT_WINNING_MSG_FMT.format( header=messages.game_sms_header(gamedb=gamedb), winning_tribe=self.winning_tribe.name, losing_tribe=self.losing_tribe.name, time=self.game_options.game_schedule.localized_time_string( self.game_options.game_schedule. daily_tribal_council_end_time), challenge_time=self.game_options.game_schedule. localized_time_string(self.game_options.game_schedule. daily_challenge_start_time)), recipient_phone_numbers=winning_player_phone_numbers)) return player_messages
def messages(self, gamedb: Database) -> List[SMSEventMessage]: player_messages = [] count_players = gamedb.count_players( from_tribe=gamedb.tribe_from_id(self.winning_player.tribe_id)) # TODO(brandon): unclear why this can't be done in a single bulk message. for player in self.losing_players: options_map = messages.players_as_formatted_options_map( players=self.losing_players, exclude_player=player) # NOTE(brandon): we perform this synchronously to guarantee that ballots are # created in the DB before SMS messages go out to users. gamedb.ballot(player_id=player.id, options=options_map.options, challenge_id=None) player_messages.append( SMSEventMessage( content=messages. NOTIFY_SINGLE_TEAM_COUNCIL_EVENT_LOSING_MSG_FMT.format( header=messages.game_sms_header(gamedb=gamedb), winner=messages.format_tiktok_username( self.winning_player.tiktok), players=count_players, time=self.game_options.game_schedule. localized_time_string(self.game_options.game_schedule. daily_challenge_end_time), options=options_map.formatted_string), recipient_phone_numbers=[player.phone_number])) options_map = messages.players_as_formatted_options_map( players=self.losing_players, exclude_player=self.winning_player) gamedb.ballot(player_id=self.winning_player.id, options=options_map.options, challenge_id=None) player_messages.append( SMSEventMessage( content=messages. NOTIFY_SINGLE_TEAM_COUNCIL_EVENT_WINNING_MSG_FMT.format( header=messages.game_sms_header(gamedb=gamedb), players=count_players, time=self.game_options.game_schedule.localized_time_string( self.game_options.game_schedule. daily_challenge_end_time), options=options_map.formatted_string), recipient_phone_numbers=[self.winning_player.phone_number])) return player_messages
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() ]) ]