automate streamer trophies - closes #1059
parent
45adf73214
commit
e68cc3595b
|
@ -39,7 +39,8 @@ final class Env(
|
|||
getRatingChart = Env.history.ratingChartApi.apply,
|
||||
getRanks = Env.user.cached.ranking.getAll,
|
||||
isDonor = Env.donation.isDonor,
|
||||
isHostingSimul = Env.simul.isHosting) _
|
||||
isHostingSimul = Env.simul.isHosting,
|
||||
isStreamer = Env.tv.isStreamer.apply) _
|
||||
|
||||
system.actorOf(Props(new actor.Renderer), name = RendererName)
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ case class UserInfo(
|
|||
nbPosts: Int,
|
||||
playTime: User.PlayTime,
|
||||
donor: Boolean,
|
||||
trophies: Trophies) {
|
||||
trophies: Trophies,
|
||||
isStreamer: Boolean) {
|
||||
|
||||
def nbRated = user.count.rated
|
||||
|
||||
|
@ -36,12 +37,18 @@ case class UserInfo(
|
|||
|
||||
def percentRated: Int = math.round(nbRated / user.count.game.toFloat * 100)
|
||||
|
||||
def allTrophies = (donor ?? List(Trophy(
|
||||
_id = "",
|
||||
user = user.id,
|
||||
kind = Trophy.Kind.Donor,
|
||||
date = org.joda.time.DateTime.now)
|
||||
)) ::: trophies
|
||||
def allTrophies = List(
|
||||
donor option Trophy(
|
||||
_id = "",
|
||||
user = user.id,
|
||||
kind = Trophy.Kind.Donor,
|
||||
date = org.joda.time.DateTime.now),
|
||||
isStreamer option Trophy(
|
||||
_id = "",
|
||||
user = user.id,
|
||||
kind = Trophy.Kind.Streamer,
|
||||
date = org.joda.time.DateTime.now)
|
||||
).flatten ::: trophies
|
||||
}
|
||||
|
||||
object UserInfo {
|
||||
|
@ -57,7 +64,8 @@ object UserInfo {
|
|||
getRatingChart: User => Fu[Option[String]],
|
||||
getRanks: String => Fu[Map[String, Int]],
|
||||
isDonor: String => Fu[Boolean],
|
||||
isHostingSimul: String => Fu[Boolean])(user: User, ctx: Context): Fu[UserInfo] =
|
||||
isHostingSimul: String => Fu[Boolean],
|
||||
isStreamer: String => Boolean)(user: User, ctx: Context): Fu[UserInfo] =
|
||||
countUsers() zip
|
||||
getRanks(user.id) zip
|
||||
(gameCached nbPlaying user.id) zip
|
||||
|
@ -89,7 +97,8 @@ object UserInfo {
|
|||
nbPosts = nbPosts,
|
||||
playTime = playTime,
|
||||
donor = isDonor,
|
||||
trophies = trophies)
|
||||
trophies = trophies,
|
||||
isStreamer = isStreamer(user.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.typesafe.config.Config
|
|||
import lila.common.PimpedConfig._
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
import scala.concurrent.duration._
|
||||
|
||||
final class Env(
|
||||
config: Config,
|
||||
|
@ -41,6 +42,14 @@ final class Env(
|
|||
coll.update(BSONDocument("_id" -> "streamer"), BSONDocument("text" -> text), upsert = true).void
|
||||
})
|
||||
|
||||
object isStreamer {
|
||||
private val cache = lila.memo.MixedCache.single[Set[String]](
|
||||
f = streamerList.lichessIds,
|
||||
timeToLive = 1 minute,
|
||||
default = Set.empty)
|
||||
def apply(id: String) = cache get true contains id
|
||||
}
|
||||
|
||||
def streamsOnAir = streaming.onAir
|
||||
|
||||
{
|
||||
|
|
|
@ -16,6 +16,10 @@ final class StreamerList(
|
|||
validate(text)._1
|
||||
}
|
||||
|
||||
private[tv] def lichessIds: Fu[Set[String]] = get map {
|
||||
_.map(_.lichessName.toLowerCase).toSet
|
||||
}
|
||||
|
||||
def validate(text: String): (List[Streamer], List[Exception]) = Try {
|
||||
ConfigFactory.parseString(text).getConfigList("streamers").toList.map { c =>
|
||||
Try {
|
||||
|
|
Loading…
Reference in New Issue