<commit_before>package views.html.mod

import cats.data.NonEmptyList
import controllers.routes
import scala.util.matching.Regex

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.richText
import lila.report.Reason
import lila.report.Report
import lila.user.User

object inquiry {

  // simul game study relay tournament
  private val commFlagRegex = """\[FLAG\] (\w+)/(\w{8})(?:/w)? (.+)(?:\n|$)""".r

  def renderAtomText(atom: lila.report.Report.Atom, highlight: Boolean) = {
    val text =
      commFlagRegex.replaceAllIn(
        atom.simplifiedText,
        m => {
          val id = m.group(2)
          val path = m.group(1) match {
            case "game"       => routes.Round.watcher(id, "white")
            case "relay"      => routes.Relay.show("-", id)
            case "tournament" => routes.Tournament.show(id)
            case "swiss"      => routes.Swiss.show(id)
            case _            => s"/${m.group(1)}/$id"
          }
          Regex.quoteReplacement(s"$netBaseUrl$path ${m.group(3)}")
        }
      )
    if (highlight) communication.highlightBad(text) else richText(text)
  }

  def apply(in: lila.mod.Inquiry)(implicit ctx: Context) = {
    def renderReport(r: lila.report.Report) =
      div(cls := "doc report")(
        r.bestAtoms(10).map { atom =>
          div(cls := "atom")(
            h3(
              reportScore(atom.score),
              userIdLink(atom.by.value.some, withOnline = false),
              " for ",
              strong(r.reason.name),
              " ",
              momentFromNow(atom.at)
            ),
            p(renderAtomText(atom, r.isComm))
          )
        }
      )

    def renderNote(r: lila.user.Note)(implicit ctx: Context) =
      (!r.dox || isGranted(_.Admin)) option div(cls := "doc note")(
        h3("by ", userIdLink(r.from.some, withOnline = false), ", ", momentFromNow(r.date)),
        p(richText(r.text, expandImg = false))
      )

    def autoNextInput = input(cls := "auto-next", tpe := "hidden", name := "next", value := "1")

    def markButton(active: Boolean) =
      submitButton(
        cls := List(
          "fbt icon" -> true,
          "active"   -> active
        )<commit_msg>fix links in inquiry reports<commit_after>package views.html.mod

import cats.data.NonEmptyList
import controllers.routes
import scala.util.matching.Regex

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.richText
import lila.report.Reason
import lila.report.Report
import lila.user.User

object inquiry {

  // simul game study relay tournament
  private val commFlagRegex = new Regex("""\[FLAG\] (\w+)/(\w{8})(?:/w)? (.+)(?:\n|$)""", "tpe", "id", "text")

  def renderAtomText(text: String, highlight: Boolean) = raw(
    commFlagRegex.replaceAllIn(
      text,
      m => {
        val id = m.group("id")
        val path = m.group("tpe") match {
          case "game"       => routes.Round.watcher(id, "white").url
          case "relay"      => routes.Relay.show("-", id).url
          case "tournament" => routes.Tournament.show(id).url
          case "swiss"      => routes.Swiss.show(id).url
          case _            => s"/${m.group("tpe")}/$id"
        }
        val link     = a(href := s"$path")(path)
        val userText = if (highlight) communication.highlightBad(m group "text") else frag(m group "text")
        Regex.quoteReplacement(s"${link.render} ${userText.render}")
      }
    )
  )

  def apply(in: lila.mod.Inquiry)(implicit ctx: Context) = {
    def renderReport(r: lila.report.Report) =
      div(cls := "doc report")(
        r.bestAtoms(10).map { atom =>
          div(cls := "atom")(
            h3(
              reportScore(atom.score),
              userIdLink(atom.by.value.some, withOnline = false),
              " for ",
              strong(r.reason.name),
              " ",
              momentFromNow(atom.at)
            ),
            p(renderAtomText(atom.simplifiedText, r.isComm))
          )
        }
      )

    def renderNote(r: lila.user.Note)(implicit ctx: Context) =
      (!r.dox || isGranted(_.Admin)) option div(cls := "doc note")(
        h3("by ", userIdLink(r.from.some, withOnline = false), ", ", momentFromNow(r.date)),
        p(richText(r.text, expandImg = false))
      )

    def autoNextInput = input(cls := "auto-next", tpe := "hidden", name := "next", value := "1")

    def markButton(active: Boolean) =
      submitButton(
        cls := List(
          "fbt icon" -> true,
          "active"   -> active
        )
{'fraction_non_alphanumeric': 0.15512048192771086, 'fraction_numerical': 0.0034423407917383822, 'mean_word_length': 2.1886145404663924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '6244955', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1488, 'n_words': 297}