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]: player_messages = [] count_players = gamedb.count_players( from_tribe=gamedb.tribe_from_id(self.winning_player.tribe_id)) for player in self.losing_players: player_messages.append( SMSEventMessage( content=messages.NOTIFY_SINGLE_TEAM_COUNCIL_EVENT_LOSING_MSG_FMT.format( header=messages.VIR_US_SMS_HEADER, 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=messages.players_as_formatted_options_list( players=self.losing_players, exclude_player=player) ), recipient_phone_numbers=player.phone_number ) ) player_messages.append( SMSEventMessage( content=messages.NOTIFY_SINGLE_TEAM_COUNCIL_EVENT_WINNING_MSG_FMT.format( header=messages.VIR_US_SMS_HEADER, players=count_players, time=self.game_options.game_schedule.localized_time_string( self.game_options.game_schedule.daily_challenge_end_time), options=messages.players_as_formatted_options_list( players=self.losing_players) ), recipient_phone_numbers=self.winning_player.phone_number ) ) return player_messages
def _tribe_count_players(tribe: Tribe, gamedb: Database) -> int: tribe = gamedb.tribe_from_id(tribe.id) return tribe.count_players