Skip to content

Commit b4c2510

Browse files
author
Racci
committed
refactor(stat channel): Warn log instead of throwing error
1 parent f0aa9fa commit b4c2510

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/main/kotlin/dev/racci/elixir/extensions/StatChannels.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.kotlindiscord.kord.extensions.extensions.Extension
44
import dev.kord.common.annotation.KordExperimental
55
import dev.kord.common.annotation.KordUnsafe
66
import dev.kord.core.behavior.channel.edit
7+
import dev.kord.core.kordLogger
78
import dev.racci.elixir.utils.GUILD_ID
89
import dev.racci.elixir.utils.MEMBER_COUNTER
910
import dev.racci.elixir.utils.STATUS_CHANNEL
@@ -14,6 +15,7 @@ import io.ktor.client.features.json.JsonFeature
1415
import io.ktor.client.request.get
1516
import kotlinx.coroutines.DelicateCoroutinesApi
1617
import kotlinx.coroutines.GlobalScope
18+
import kotlinx.coroutines.TimeoutCancellationException
1719
import kotlinx.coroutines.delay
1820
import kotlinx.coroutines.flow.count
1921
import kotlinx.coroutines.launch
@@ -43,10 +45,17 @@ class StatChannels : Extension() {
4345

4446
while (loaded) {
4547
// Time it out in 1.5 seconds so we don't end up blocked
46-
val tStatus = withTimeoutOrNull<Query?>(1500.milliseconds) {
47-
try {
48-
return@withTimeoutOrNull client.get("https://mcapi.xdefcon.com/server/$STATUS_SERVER/status/json")
49-
} catch (ignored: ServerResponseException) { return@withTimeoutOrNull null }
48+
val tStatus: Query? = try {
49+
withTimeoutOrNull(1500.milliseconds) {
50+
try {
51+
return@withTimeoutOrNull client.get("https://mcapi.xdefcon.com/server/$STATUS_SERVER/status/json")
52+
} catch (ignored: ServerResponseException) {
53+
return@withTimeoutOrNull null
54+
}
55+
}
56+
} catch (ignored: TimeoutCancellationException) {
57+
kordLogger.warn { "Timeout while checking server status" }
58+
null
5059
}
5160
// We only want to change the name if it needs changing
5261
if (tStatus != null && status != tStatus.online) {

0 commit comments

Comments
 (0)