File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
src/test/kotlin/io/github/freya022/botcommands/test/utils Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ package io.github.freya022.botcommands.test.utils
2+
3+ import ch.qos.logback.classic.Level
4+ import ch.qos.logback.classic.Logger
5+ import dev.minn.jda.ktx.coroutines.await
6+ import io.github.freya022.botcommands.api.core.utils.awaitCatching
7+ import kotlinx.coroutines.sync.Mutex
8+ import kotlinx.coroutines.sync.withLock
9+ import net.dv8tion.jda.api.requests.RestAction
10+ import net.dv8tion.jda.internal.requests.Requester
11+ import org.slf4j.LoggerFactory
12+
13+ private val mutex = Mutex ()
14+
15+ suspend fun <T > RestAction<T>.awaitAndLog (): T {
16+ val logger = LoggerFactory .getLogger(Requester ::class .java.name) as Logger
17+ return mutex.withLock {
18+ val oldLevel = logger.level
19+ try {
20+ logger.level = Level .TRACE
21+ await()
22+ } finally {
23+ logger.level = oldLevel
24+ }
25+ }
26+ }
27+
28+ suspend fun RestAction <* >.awaitAndLogCatching () {
29+ val logger = LoggerFactory .getLogger(Requester ::class .java.name) as Logger
30+ val oldLevel = logger.level
31+ mutex.withLock {
32+ try {
33+ logger.level = Level .TRACE
34+ awaitCatching().onFailure { it.printStackTrace() }
35+ } finally {
36+ logger.level = oldLevel
37+ }
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments