multiple tavern monitor channels - closes lichess-org/tavern#80

pull/8513/head
Thibault Duplessis 2021-03-30 15:02:18 +02:00
parent 85e1fd7380
commit 491358ace2
2 changed files with 39 additions and 18 deletions

View File

@ -89,17 +89,17 @@ final class SlackApi(
)
)
def monitorMod(modId: User.ID, icon: String, text: String): Funit =
def monitorMod(modId: User.ID, icon: String, text: String, monitorType: MonitorType): Funit =
lightUser(modId) flatMap {
_ ?? { mod =>
client(
val msg =
SlackMessage(
username = mod.name,
icon = "scroll",
text = s":$icon: ${linkifyUsers(text)}",
channel = "tavern-monitor"
channel = rooms.tavernMonitor(monitorType)
)
)
client(msg) >> client(msg.copy(channel = rooms.tavernMonitorAll))
}
}
@ -111,7 +111,7 @@ final class SlackApi(
username = mod.name,
icon = "scroll",
text = s":$icon: ${linkifyUsers(text)}",
channel = "tavern-log"
channel = rooms.tavernLog
)
)
}
@ -291,20 +291,30 @@ final class SlackApi(
)
}
private object SlackApi {
object SlackApi {
object rooms {
val general = "team"
val tavern = "tavern"
val tavernBots = "tavern-bots"
val tavernNotes = "tavern-notes"
val tavernAppeal = "tavern-appeal"
val signups = "signups"
val broadcast = "broadcast"
val devNoise = "dev-noise"
sealed trait MonitorType
object MonitorType {
case object Hunt extends MonitorType
case object Comm extends MonitorType
case object Other extends MonitorType
}
object stage {
private[irc] object rooms {
val general = "team"
val tavern = "tavern"
val tavernBots = "tavern-bots"
val tavernNotes = "tavern-notes"
val tavernAppeal = "tavern-appeal"
val tavernLog = "tavern-log"
val signups = "signups"
val broadcast = "broadcast"
val devNoise = "dev-noise"
def tavernMonitor(tpe: MonitorType) = s"tavern-monitor-${tpe.toString.toLowerCase}"
val tavernMonitorAll = "tavern-monitor-all"
}
private[irc] object stage {
val name = "stage.lichess.org"
val icon = "volcano"
}

View File

@ -6,8 +6,9 @@ import lila.db.dsl._
import lila.report.{ Mod, ModId, Report, Suspect }
import lila.security.Permission
import lila.user.{ Holder, User, UserRepo }
import lila.irc.SlackApi
final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, slackApi: lila.irc.SlackApi)(implicit
final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, slackApi: SlackApi)(implicit
ec: scala.concurrent.ExecutionContext
) {
@ -290,7 +291,17 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, slackApi: lila.irc.S
}
val text = s"""${m.showAction.capitalize} ${m.user.??(u => s"@$u ")}${~m.details}"""
userRepo.isMonitoredMod(m.mod) flatMap {
_ ?? slackApi.monitorMod(m.mod, icon = icon, text = text)
_ ?? {
val monitorType = m.action match {
case M.engine | M.unengine | M.booster | M.unbooster | M.closeAccount | M.reopenAccount =>
SlackApi.MonitorType.Hunt
case M.troll | M.untroll | M.chatTimeout | M.closeTopic | M.openTopic | M.disableTeam |
M.enableTeam =>
SlackApi.MonitorType.Hunt
case _ => SlackApi.MonitorType.Other
}
slackApi.monitorMod(m.mod, icon = icon, text = text, monitorType)
}
}
slackApi.logMod(m.mod, icon = icon, text = text)
}