Create a zulip note whenever a mod sends to Zulip
close https://github.com/lichess-org/tavern/issues/136pull/9886/head
parent
1e9d0eaa4e
commit
0eda25ce08
|
@ -215,24 +215,26 @@ final class Mod(
|
|||
env.report.api.inquiries ofModId me.id flatMap {
|
||||
case None => Redirect(routes.Report.list).fuccess
|
||||
case Some(report) =>
|
||||
env.user.lightUserApi asyncFallback report.user flatMap { user =>
|
||||
import lila.report.Room
|
||||
import lila.irc.IrcApi.ModDomain
|
||||
env.irc.api.inquiry(
|
||||
user = user,
|
||||
mod = me,
|
||||
domain = report.room match {
|
||||
case Room.Cheat | Room.Boost => ModDomain.Hunt
|
||||
case Room.Comm => ModDomain.Comm
|
||||
// spontaneous inquiry
|
||||
case _ if Granter(_.Admin)(me.user) => ModDomain.Admin
|
||||
case _ if Granter(_.Hunter)(me.user) => ModDomain.Hunt // heuristic
|
||||
case _ if Granter(_.Shusher)(me.user) => ModDomain.Comm
|
||||
case _ => ModDomain.Admin
|
||||
env.user.repo named report.user flatMap {
|
||||
_ ?? { user =>
|
||||
import lila.report.Room
|
||||
import lila.irc.IrcApi.ModDomain
|
||||
env.irc.api.inquiry(
|
||||
user = user,
|
||||
mod = me,
|
||||
domain = report.room match {
|
||||
case Room.Cheat | Room.Boost => ModDomain.Hunt
|
||||
case Room.Comm => ModDomain.Comm
|
||||
// spontaneous inquiry
|
||||
case _ if Granter(_.Admin)(me.user) => ModDomain.Admin
|
||||
case _ if Granter(_.Hunter)(me.user) => ModDomain.Hunt // heuristic
|
||||
case _ if Granter(_.Shusher)(me.user) => ModDomain.Comm
|
||||
case _ => ModDomain.Admin
|
||||
|
||||
},
|
||||
room = if (report.isSpontaneous) "Spontaneous inquiry" else report.room.name
|
||||
) inject NoContent
|
||||
},
|
||||
room = if (report.isSpontaneous) "Spontaneous inquiry" else report.room.name
|
||||
) inject NoContent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ final class IrcApi(
|
|||
zulip(_.mod.commsPrivate, "burst")(md)
|
||||
}
|
||||
|
||||
def inquiry(user: LightUser, mod: Holder, domain: ModDomain, room: String): Funit = {
|
||||
def inquiry(user: User, mod: Holder, domain: ModDomain, room: String): Funit = {
|
||||
val stream = domain match {
|
||||
case ModDomain.Comm => ZulipClient.stream.mod.commsPrivate
|
||||
case ModDomain.Hunt => ZulipClient.stream.mod.hunterCheat
|
||||
|
@ -32,17 +32,22 @@ final class IrcApi(
|
|||
.map(_.headOption.filter(_.date isAfter DateTime.now.minusMinutes(5)))
|
||||
.flatMap {
|
||||
case None =>
|
||||
zulip(stream, "/" + user.name)(
|
||||
zulip.sendAndGetLink(stream, "/" + user.username)(
|
||||
s"${markdown.userLink(mod.user.username)} :monkahmm: is looking at a $room report about **${markdown
|
||||
.userLink(user.name)}**"
|
||||
.userLink(user.username)}**"
|
||||
)
|
||||
case Some(note) =>
|
||||
zulip(stream, "/" + user.name)(
|
||||
zulip.sendAndGetLink(stream, "/" + user.username)(
|
||||
s"${markdown.modLink(mod.user.username)} :pepenote: **${markdown
|
||||
.userLink(user.name)}** (${markdown.userNotesLink(user.name)}):\n" +
|
||||
.userLink(user.username)}** (${markdown.userNotesLink(user.username)}):\n" +
|
||||
markdown.linkifyUsers(note.text take 2000)
|
||||
)
|
||||
}
|
||||
.flatMap {
|
||||
_ ?? { ZulipLink =>
|
||||
noteApi.write(user, s"$domain discussion: $ZulipLink", mod.user, modOnly = true, dox = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def userModNote(modName: String, username: String, note: String): Funit =
|
||||
|
|
|
@ -27,12 +27,15 @@ final private class ZulipClient(ws: StandaloneWSClient, config: ZulipClient.Conf
|
|||
|
||||
def sendAndGetLink(stream: ZulipClient.stream.Selector, topic: String)(
|
||||
content: String
|
||||
): Fu[Option[String]] = sendAndGetLink(stream(ZulipClient.stream), topic)(content)
|
||||
|
||||
def sendAndGetLink(stream: String, topic: String)(
|
||||
content: String
|
||||
): Fu[Option[String]] = {
|
||||
val streamString = stream(ZulipClient.stream)
|
||||
send(ZulipMessage(stream = streamString, topic = topic, content = content)).map {
|
||||
send(ZulipMessage(stream = stream, topic = topic, content = content)).map {
|
||||
// Can be `None` if the message was rate-limited (i.e Someone already created a conv a few minutes earlier)
|
||||
_.map { msgId =>
|
||||
s"https://${config.domain}/#narrow/stream/${urlencode(streamString)}/topic/${urlencode(topic)}/near/$msgId"
|
||||
s"https://${config.domain}/#narrow/stream/${urlencode(stream)}/topic/${urlencode(topic)}/near/$msgId"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue