<commit_before>package lila.challenge

import scala.concurrent.ExecutionContext

import lila.common.{ LightUser, Template }
import lila.user.{ LightUserApi, User }

final class ChallengeMsg(msgApi: lila.msg.MsgApi, lightUserApi: LightUserApi)(implicit
    ec: ExecutionContext
) {

  def onApiPair(challenge: Challenge)(managedBy: User, template: Option[Template]): Funit =
    challenge.userIds.map(lightUserApi.async).sequenceFu.flatMap {
      _.flatten match {
        case List(u1, u2) => onApiPair(challenge.id, u1, u2)(managedBy.id, template)
        case _            => funit
      }
    }

  def onApiPair(gameId: lila.game.Game.ID, u1: LightUser, u2: LightUser)(
      managedById: User.ID,
      template: Option[Template]
  ): Funit =
    List(u1 -> u2, u2 -> u1)
      .map { case (u1, u2) =>
        val msg = template
          .fold("Your game with {opponent} is ready: {game}.")(_.value)
          .replace("{opponent}", s"@${u2.name}")
          .replace("{game}", s"#${gameId}")
        msgApi.post(managedById, u1.id, msg, multi = true)<commit_msg>add {player} placeholder - for lichess-org/api#96<commit_after>package lila.challenge

import scala.concurrent.ExecutionContext

import lila.common.{ LightUser, Template }
import lila.user.{ LightUserApi, User }

final class ChallengeMsg(msgApi: lila.msg.MsgApi, lightUserApi: LightUserApi)(implicit
    ec: ExecutionContext
) {

  def onApiPair(challenge: Challenge)(managedBy: User, template: Option[Template]): Funit =
    challenge.userIds.map(lightUserApi.async).sequenceFu.flatMap {
      _.flatten match {
        case List(u1, u2) => onApiPair(challenge.id, u1, u2)(managedBy.id, template)
        case _            => funit
      }
    }

  def onApiPair(gameId: lila.game.Game.ID, u1: LightUser, u2: LightUser)(
      managedById: User.ID,
      template: Option[Template]
  ): Funit =
    List(u1 -> u2, u2 -> u1)
      .map { case (u1, u2) =>
        val msg = template
          .fold("Your game with {opponent} is ready: {game}.")(_.value)
          .replace("{player}", s"@${u1.name}")
          .replace("{opponent}", s"@${u2.name}")
          .replace("{game}", s"#${gameId}")
        msgApi.post(managedById, u1.id, msg, multi = true)
{'fraction_non_alphanumeric': 0.14723097703737056, 'fraction_numerical': 0.013957676722197209, 'mean_word_length': 3.1072088724584104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7050021', 'n_tokens_mistral': 764, 'n_tokens_neox': 747, 'n_words': 161}