discard mistyped whispers

pull/2508/head
Thibault Duplessis 2016-11-06 18:50:22 +01:00
parent b9929f7230
commit b0153faf48
1 changed files with 12 additions and 9 deletions

View File

@ -31,15 +31,18 @@ final class Messenger(
private val whisperCommands = List("/whisper ", "/w ")
def owner(gameId: String, member: Member, text: String) =
chat ! (member.userId match {
case Some(userId) =>
whisperCommands.collectFirst {
case command if text startsWith command =>
UserTalk(watcherId(gameId), userId, text drop command.size)
} | UserTalk(gameId, userId, text, public = false)
case None => PlayerTalk(gameId, member.color.white, text)
})
def owner(gameId: String, member: Member, text: String) = (member.userId match {
case Some(userId) =>
whisperCommands.collectFirst {
case command if text startsWith command =>
UserTalk(watcherId(gameId), userId, text drop command.size)
} orElse {
if (text startsWith "/") none // mistyped command?
else UserTalk(gameId, userId, text, public = false).some
}
case None =>
PlayerTalk(gameId, member.color.white, text).some
}) foreach chat.!
private def watcherId(gameId: String) = s"$gameId/w"
}