Skip to content

Commit ba646ad

Browse files
authored
Merge pull request #103 from the-programmers-hangout/test/add-logging
test: add logging to debug slowness
2 parents 0280725 + 783b9ac commit ba646ad

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies {
1616
implementation("me.jakejmattson:DiscordKt:${Versions.DISCORDKT}")
1717
implementation("org.litote.kmongo:kmongo-coroutine:4.2.8")
1818
implementation("joda-time:joda-time:2.10.10")
19+
implementation("org.slf4j:slf4j-simple:1.7.30")
1920
}
2021

2122
tasks {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.ddivad.judgebot.preconditions
2+
3+
import me.jakejmattson.discordkt.api.dsl.precondition
4+
import me.jakejmattson.discordkt.api.extensions.sanitiseMentions
5+
6+
fun commandLogger() = precondition {
7+
command ?: return@precondition fail()
8+
9+
val args = rawInputs.commandArgs.joinToString()
10+
11+
if (args.length > 1500)
12+
return@precondition fail("Command is too long (${args.length} chars, max: 1500")
13+
14+
if (guild != null) {
15+
val message =
16+
"${author.tag} :: ${author.id.value} :: " +
17+
"Invoked `${command!!.names.first()}`" +
18+
if (args.isEmpty()) "" else " Args: ${args.sanitiseMentions(discord)}"
19+
20+
println(message)
21+
return@precondition
22+
}
23+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.slf4j.simpleLogger.defaultLogLevel=trace
2+
org.slf4j.simpleLogger.showDateTime=true

0 commit comments

Comments
 (0)