add chat /nicks command
This commit is contained in:
parent
77523fc54a
commit
7b0ae42010
|
@ -18,7 +18,7 @@ private[chat] final class ChatActor(
|
|||
bus: Bus,
|
||||
relationApi: lila.relation.RelationApi,
|
||||
prefApi: PrefApi,
|
||||
makeCommander: () => Commander) extends Actor {
|
||||
makeCommander: () ⇒ Commander) extends Actor {
|
||||
|
||||
private val members = collection.mutable.Map[String, ChatMember]()
|
||||
|
||||
|
@ -82,6 +82,11 @@ private[chat] final class ChatActor(
|
|||
reload(member)
|
||||
}
|
||||
|
||||
case WithChanNicks(key, f) ⇒ members.values
|
||||
.filter(_ hasActiveChan key)
|
||||
.map(_.userId).toList.distinct
|
||||
.map(namer.user).sequenceFu foreach f
|
||||
|
||||
case Input(uid, o) ⇒ (o str "t") |@| (o obj "d") |@| (members get uid) apply {
|
||||
case (typ, data, member) ⇒ typ match {
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ private[chat] final class ChatMember(
|
|||
!blocks(line.userId)
|
||||
}
|
||||
|
||||
def hasActiveChan = head.activeChanKeys contains _
|
||||
|
||||
def tell(msg: JsValue) {
|
||||
channel push msg
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ import lila.socket.SocketMember
|
|||
import lila.user.{ User, UserRepo }
|
||||
|
||||
private[chat] final class Commander(
|
||||
modApi: lila.mod.ModApi) extends Actor {
|
||||
modApi: lila.mod.ModApi,
|
||||
namer: Namer) extends Actor {
|
||||
|
||||
val chat = context.parent
|
||||
|
||||
|
@ -23,6 +24,7 @@ private[chat] final class Commander(
|
|||
case Command(chanOption, member, text) ⇒ text.split(' ').toList match {
|
||||
|
||||
case "help" :: "tutorial" :: _ ⇒ flash(member, tutorial)
|
||||
case "help" :: "mod" :: _ ⇒ flash(member, modHelp)
|
||||
case "help" :: _ ⇒ flash(member, help)
|
||||
|
||||
case "open" :: _ ⇒ chat ! SetOpen(member, true)
|
||||
|
@ -30,17 +32,27 @@ private[chat] final class Commander(
|
|||
|
||||
case "query" :: username :: _ ⇒ chat ! Query(member, username.toLowerCase)
|
||||
|
||||
case "join" :: chanName :: _ ⇒ Chan parse chanName match {
|
||||
case "join" :: chanKey :: _ ⇒ Chan parse chanKey match {
|
||||
case Some(chan) ⇒ chat ! Join(member, chan)
|
||||
case None ⇒ flash(member, s"The channel $chanName does not exist.")
|
||||
case None ⇒ flash(member, s"The channel $chanKey does not exist.")
|
||||
}
|
||||
case "show" :: chanName :: _ ⇒ Chan parse chanName foreach { chan ⇒
|
||||
case "show" :: chanKey :: _ ⇒ Chan parse chanKey foreach { chan ⇒
|
||||
chat ! Activate(member, chan)
|
||||
}
|
||||
case "hide" :: chanName :: _ ⇒ Chan parse chanName foreach { chan ⇒
|
||||
case "hide" :: chanKey :: _ ⇒ Chan parse chanKey foreach { chan ⇒
|
||||
chat ! DeActivate(member, chan)
|
||||
}
|
||||
|
||||
case "nicks" :: _ ⇒ chanOption foreach { chan ⇒
|
||||
(UserRepo byId member.userId flatten s"No such user: $member.userId") foreach { user ⇒
|
||||
namer.chan(chan, user) foreach { named ⇒
|
||||
chat ! WithChanNicks(chan.key, { nicks ⇒
|
||||
flash(member, s"Users in ${named.name}: ${nicks.sorted.mkString(", ")}")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case ("rematch" | "resign" | "abort" | "takeback") :: _ ⇒ gameOnlyCommand(member)
|
||||
case MoveRegex(orig, dest) :: _ ⇒ gameOnlyCommand(member)
|
||||
|
||||
|
@ -92,5 +104,10 @@ _______________________ user commands ______________________
|
|||
_______________________ game commands ______________________
|
||||
/e2e4 move the piece on e2 to e4
|
||||
/abort, /resign, /takeback, /rematch
|
||||
""") + "</pre>"
|
||||
|
||||
val modHelp = "<pre>" + escapeXml("""
|
||||
_______________________ mod commands _______________________
|
||||
/troll <user> toggle user troll status
|
||||
""") + "</pre>"
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@ final class Env(
|
|||
relationApi = relationApi,
|
||||
prefApi = prefApi,
|
||||
makeCommander = () ⇒ new Commander(
|
||||
modApi = modApi
|
||||
modApi = modApi,
|
||||
namer = namer
|
||||
))))
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@ private[chat] final class Namer(
|
|||
getUsername: String ⇒ Fu[String],
|
||||
getTeamName: String ⇒ Fu[Option[String]]) {
|
||||
|
||||
def line(l: Line): Fu[NamedLine] = getUsername(l.userId) map { NamedLine(l, _) }
|
||||
val user = getUsername
|
||||
|
||||
def line(l: Line): Fu[NamedLine] = user(l.userId) map { NamedLine(l, _) }
|
||||
|
||||
def chan(c: Chan, as: User): Fu[NamedChan] =
|
||||
chanCache(c -> as) map { NamedChan(c, _) }
|
||||
|
@ -29,10 +31,10 @@ private[chat] final class Namer(
|
|||
case (c@GameWatcherChan(id), _) ⇒
|
||||
GameRepo game id flatten s"No game for chan $c" flatMap nameWatcherChan
|
||||
|
||||
case (c@GamePlayerChan(id), user) ⇒
|
||||
case (c@GamePlayerChan(id), u) ⇒
|
||||
GameRepo game id flatten s"No game for chan $c" flatMap { game ⇒
|
||||
(game player user).fold(nameWatcherChan(game)) { player ⇒
|
||||
lila.game.Namer.player(game opponent player, false)(getUsername) map { opponent ⇒
|
||||
(game player u).fold(nameWatcherChan(game)) { player ⇒
|
||||
lila.game.Namer.player(game opponent player, false)(user) map { opponent ⇒
|
||||
s"Game: $opponent"
|
||||
}
|
||||
}
|
||||
|
@ -43,10 +45,10 @@ private[chat] final class Namer(
|
|||
_ + " tournament"
|
||||
}
|
||||
|
||||
case (c@UserChan(u1, u2), user) ⇒
|
||||
if (user.id == u1) getUsername(u2)
|
||||
else if (user.id == u2) getUsername(u1)
|
||||
else fufail(s"${user.id} can't see $c")
|
||||
case (c@UserChan(u1, u2), u) ⇒
|
||||
if (u.id == u1) user(u2)
|
||||
else if (u.id == u2) user(u1)
|
||||
else fufail(s"${u.id} can't see $c")
|
||||
|
||||
case (c@TeamChan(id), _) ⇒ getTeamName(id) map (_ | id)
|
||||
|
||||
|
@ -58,5 +60,5 @@ private[chat] final class Namer(
|
|||
}
|
||||
|
||||
private def nameWatcherChan(game: Game) =
|
||||
lila.game.Namer.players(game, false)(getUsername) map { case (p1, p2) ⇒ s"$p1 vs $p2" }
|
||||
lila.game.Namer.players(game, false)(user) map { case (p1, p2) ⇒ s"$p1 vs $p2" }
|
||||
}
|
||||
|
|
|
@ -14,4 +14,6 @@ case class Join(member: ChatMember, chan: Chan)
|
|||
|
||||
case class Activate(member: ChatMember, chan: Chan)
|
||||
case class DeActivate(member: ChatMember, chan: Chan)
|
||||
|
||||
case class WithChanNicks(key: String, f: List[String] => Unit)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue