2017-12-27 21:56:36 -07:00
|
|
|
package lila.streamer
|
|
|
|
|
|
|
|
import akka.actor._
|
2019-11-30 16:34:58 -07:00
|
|
|
import com.softwaremill.macwire._
|
|
|
|
import io.methvin.play.autoconfig._
|
|
|
|
import play.api.Configuration
|
2019-09-21 01:14:32 -06:00
|
|
|
import scala.concurrent.duration._
|
2017-12-27 21:56:36 -07:00
|
|
|
|
2019-11-30 16:34:58 -07:00
|
|
|
import lila.common.config._
|
2018-11-15 22:20:12 -07:00
|
|
|
|
2019-11-30 16:34:58 -07:00
|
|
|
@Module
|
2019-11-30 19:29:40 -07:00
|
|
|
private class StreamerConfig(
|
2019-11-30 16:34:58 -07:00
|
|
|
@ConfigName("collection.streamer") val streamerColl: CollName,
|
|
|
|
@ConfigName("paginator.max_per_page") val paginatorMaxPerPage: MaxPerPage,
|
|
|
|
@ConfigName("streaming.keyword") val keyword: Stream.Keyword,
|
2021-03-02 01:19:59 -07:00
|
|
|
@ConfigName("streaming.google.api_key") val googleApiKey: Secret,
|
|
|
|
@ConfigName("streaming.twitch") val twitchConfig: TwitchConfig
|
2019-11-30 16:34:58 -07:00
|
|
|
)
|
2021-03-03 04:20:14 -07:00
|
|
|
private class TwitchConfig(@ConfigName("client_id") val clientId: String, val secret: Secret)
|
2019-11-30 16:34:58 -07:00
|
|
|
|
2019-12-03 23:45:33 -07:00
|
|
|
@Module
|
2017-12-27 21:56:36 -07:00
|
|
|
final class Env(
|
2019-11-30 16:34:58 -07:00
|
|
|
appConfig: Configuration,
|
2020-08-07 08:22:26 -06:00
|
|
|
ws: play.api.libs.ws.StandaloneWSClient,
|
2018-11-15 20:34:19 -07:00
|
|
|
settingStore: lila.memo.SettingStore.Builder,
|
2019-12-04 21:32:03 -07:00
|
|
|
isOnline: lila.socket.IsOnline,
|
2019-12-23 18:01:45 -07:00
|
|
|
cacheApi: lila.memo.CacheApi,
|
2021-09-07 11:56:02 -06:00
|
|
|
picfitApi: lila.memo.PicfitApi,
|
2018-01-01 21:17:36 -07:00
|
|
|
notifyApi: lila.notify.NotifyApi,
|
2019-11-30 16:34:58 -07:00
|
|
|
userRepo: lila.user.UserRepo,
|
2019-12-01 12:25:25 -07:00
|
|
|
timeline: lila.hub.actors.Timeline,
|
2021-09-09 00:16:33 -06:00
|
|
|
db: lila.db.Db
|
2020-06-24 03:37:18 -06:00
|
|
|
)(implicit
|
|
|
|
ec: scala.concurrent.ExecutionContext,
|
|
|
|
system: ActorSystem
|
|
|
|
) {
|
2017-12-27 21:56:36 -07:00
|
|
|
|
2021-03-02 01:19:59 -07:00
|
|
|
implicit private val twitchLoader = AutoConfig.loader[TwitchConfig]
|
2019-12-13 07:30:20 -07:00
|
|
|
implicit private val keywordLoader = strLoader(Stream.Keyword.apply)
|
|
|
|
private val config = appConfig.get[StreamerConfig]("streamer")(AutoConfig.loader)
|
2017-12-27 21:56:36 -07:00
|
|
|
|
2019-11-30 16:34:58 -07:00
|
|
|
private lazy val streamerColl = db(config.streamerColl)
|
2017-12-27 21:56:36 -07:00
|
|
|
|
2018-11-15 20:34:19 -07:00
|
|
|
lazy val alwaysFeaturedSetting = {
|
2020-07-24 01:55:29 -06:00
|
|
|
import lila.memo.SettingStore.UserIds._
|
|
|
|
import lila.common.UserIds
|
|
|
|
settingStore[UserIds](
|
2018-11-15 20:34:19 -07:00
|
|
|
"streamerAlwaysFeatured",
|
2020-07-24 01:55:29 -06:00
|
|
|
default = UserIds(Nil),
|
2020-08-16 06:43:26 -06:00
|
|
|
text =
|
|
|
|
"Twitch streamers who get featured without the keyword - lichess usernames separated by a comma".some
|
2018-11-15 20:34:19 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-30 14:12:42 -06:00
|
|
|
lazy val homepageMaxSetting =
|
|
|
|
settingStore[Int](
|
|
|
|
"streamerHomepageMax",
|
|
|
|
default = 6,
|
|
|
|
text = "Max streamers on homepage".some
|
|
|
|
)
|
|
|
|
|
2019-11-30 16:34:58 -07:00
|
|
|
lazy val api: StreamerApi = wire[StreamerApi]
|
2017-12-28 08:53:52 -07:00
|
|
|
|
2019-11-30 16:34:58 -07:00
|
|
|
lazy val pager = wire[StreamerPager]
|
2017-12-28 14:56:58 -07:00
|
|
|
|
2021-03-02 01:19:59 -07:00
|
|
|
private lazy val twitchApi: TwitchApi = wire[TwitchApi]
|
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
private val streamingActor = system.actorOf(
|
|
|
|
Props(
|
|
|
|
new Streaming(
|
|
|
|
ws = ws,
|
|
|
|
api = api,
|
|
|
|
isOnline = isOnline,
|
|
|
|
timeline = timeline,
|
|
|
|
keyword = config.keyword,
|
|
|
|
alwaysFeatured = alwaysFeaturedSetting.get _,
|
|
|
|
googleApiKey = config.googleApiKey,
|
2021-03-02 01:19:59 -07:00
|
|
|
twitchApi = twitchApi
|
2019-12-13 07:30:20 -07:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2018-01-01 15:13:13 -07:00
|
|
|
|
2019-11-30 16:34:58 -07:00
|
|
|
lazy val liveStreamApi = wire[LiveStreamApi]
|
2018-01-01 15:13:13 -07:00
|
|
|
|
2020-09-21 01:28:28 -06:00
|
|
|
lila.common.Bus.subscribeFun("adjustCheater") { case lila.hub.actorApi.mod.MarkCheater(userId, true) =>
|
2020-09-29 01:51:32 -06:00
|
|
|
api.demote(userId).unit
|
2018-08-22 07:48:03 -06:00
|
|
|
}
|
2019-09-21 01:14:32 -06:00
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
system.scheduler.scheduleWithFixedDelay(1 hour, 1 day) { () =>
|
2020-09-29 01:51:32 -06:00
|
|
|
api.autoDemoteFakes.unit
|
2019-09-21 01:14:32 -06:00
|
|
|
}
|
2017-12-27 21:56:36 -07:00
|
|
|
}
|