Skip to content

Commit

Permalink
Fix legacy fabric and change status to servers served
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <[email protected]>
  • Loading branch information
shedaniel committed May 19, 2021
1 parent e0eb979 commit 2bf1aa8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repositories {
}

dependencies {
implementation("me.shedaniel:linkie-core:1.0.74") {
implementation("me.shedaniel:linkie-core:1.0.76") {
exclude module: "korio"
}
implementation("com.discord4j:discord4j-core:3.1.3") {
Expand Down
32 changes: 31 additions & 1 deletion src/main/kotlin/me/shedaniel/linkie/discord/LinkieBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

package me.shedaniel.linkie.discord

import com.soywiz.klock.TimeSpan
import com.soywiz.klock.minutes
import com.soywiz.klock.seconds
import discord4j.core.`object`.presence.Activity
import discord4j.core.`object`.presence.Presence
import discord4j.core.event.domain.lifecycle.ReadyEvent
Expand All @@ -27,7 +30,10 @@ import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.shedaniel.linkie.LinkieConfig
import me.shedaniel.linkie.MappingsEntryType
Expand Down Expand Up @@ -67,6 +73,8 @@ import me.shedaniel.linkie.namespaces.MojangSrgNamespace
import me.shedaniel.linkie.namespaces.PlasmaNamespace
import me.shedaniel.linkie.namespaces.YarnNamespace
import me.shedaniel.linkie.namespaces.YarrnNamespace
import me.shedaniel.linkie.utils.getMillis
import me.shedaniel.linkie.utils.info
import java.io.File
import java.util.*

Expand Down Expand Up @@ -114,7 +122,29 @@ fun main() {
// slashCommands.register()

event<ReadyEvent> {
gateway.updatePresence(Presence.online(Activity.watching("cool mappings"))).subscribe()
cycle(5.minutes, delay = 5.seconds) {
gateway.guilds.count().subscribe { size ->
info("Serving on $size servers")
gateway.updatePresence(Presence.online(Activity.watching("Serving on $size servers"))).subscribe()
}
}
}
}
}

fun cycle(time: TimeSpan, delay: TimeSpan = TimeSpan.ZERO, doThing: CoroutineScope.() -> Unit) {
val cycleMs = time.millisecondsLong

var nextDelay = getMillis() - cycleMs + delay.millisecondsLong
CoroutineScope(Dispatchers.Default).launch {
while (true) {
if (getMillis() > nextDelay + cycleMs) {
launch {
doThing()
}
nextDelay = getMillis()
}
delay(1000)
}
}
}
Expand Down

0 comments on commit 2bf1aa8

Please sign in to comment.