From e56b7f5b13f051235927c838c742cfabd71a5fb6 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 7 Jun 2022 20:12:48 +0800 Subject: [PATCH] Try to limit Signed-off-by: shedaniel --- build.gradle | 15 +++++++-------- .../linkie/discord/handler/CommandHandler.kt | 2 +- .../linkie/discord/scommands/SlashCommands.kt | 10 ++++------ .../linkie/discord/LinkieThrowableHandler.kt | 4 ++-- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 2f59b50..402a0ae 100644 --- a/build.gradle +++ b/build.gradle @@ -59,29 +59,28 @@ dependencies { implementation("me.shedaniel:linkie-core:1.0.103") { exclude module: "korio" } - discord_apiImplementation("com.github.Discord4J.Discord4J:discord4j-core:5f08aa8") { + discord_apiImplementation("com.github.Discord4J.Discord4J:discord4j-core:1a710e96") { force true } // compile("com.github.shadorc.discord4j:discord4j-core:217336e") { // force = true // } - implementation('com.soywiz.korlibs.korio:korio-jvm:2.6.2') { + implementation('com.soywiz.korlibs.korio:korio-jvm:2.7.0') { exclude module: "kds" exclude module: "klock" exclude module: "klogger" exclude module: "krypto" exclude module: "kmem" } - implementation('com.soywiz.korlibs.kds:kds-jvm:2.6.2') - implementation('com.soywiz.korlibs.klock:klock-jvm:2.6.2') - implementation('com.soywiz.korlibs.klogger:klogger-jvm:2.6.2') - implementation('com.soywiz.korlibs.krypto:krypto-jvm:2.6.2') - implementation('com.soywiz.korlibs.kmem:kmem-jvm:2.6.2') + implementation('com.soywiz.korlibs.kds:kds-jvm:2.7.0') + implementation('com.soywiz.korlibs.klock:klock-jvm:2.7.0') + implementation('com.soywiz.korlibs.klogger:klogger-jvm:2.7.0') + implementation('com.soywiz.korlibs.krypto:krypto-jvm:2.7.0') + implementation('com.soywiz.korlibs.kmem:kmem-jvm:2.7.0') implementation 'org.graalvm.js:js-scriptengine:22.0.0.2' implementation 'org.graalvm.js:js:22.0.0.2' discord_apiImplementation "io.ktor:ktor-server-core:$ktor_version" discord_apiImplementation "io.ktor:ktor-server-netty:$ktor_version" - implementation "com.github.shedaniel:CurseMetaApi:0.2" testDiscordApiImplementation 'org.jetbrains.kotlin:kotlin-test-junit5:1.6.10' // exclude(module: "truffle-api") // compile("org.graalvm.sdk:graal-sdk:20.2.0") diff --git a/src/discord_api/kotlin/me/shedaniel/linkie/discord/handler/CommandHandler.kt b/src/discord_api/kotlin/me/shedaniel/linkie/discord/handler/CommandHandler.kt index 3e0e70c..93f0862 100644 --- a/src/discord_api/kotlin/me/shedaniel/linkie/discord/handler/CommandHandler.kt +++ b/src/discord_api/kotlin/me/shedaniel/linkie/discord/handler/CommandHandler.kt @@ -143,7 +143,7 @@ open class SimpleThrowableHandler : ThrowableHandler { title("Error Occurred") color(Color.RED) basicEmbed(user) - addField("Error occurred while processing the command:", throwable.javaClass.simpleName + ": " + (throwable.localizedMessage ?: "Unknown Message"), false) + addField("Error occurred while processing the command:", throwable.javaClass.simpleName + ": " + (throwable.localizedMessage ?: "Unknown Message").take(800), false) } } } diff --git a/src/discord_api/kotlin/me/shedaniel/linkie/discord/scommands/SlashCommands.kt b/src/discord_api/kotlin/me/shedaniel/linkie/discord/scommands/SlashCommands.kt index 464f2a4..dd3ad11 100644 --- a/src/discord_api/kotlin/me/shedaniel/linkie/discord/scommands/SlashCommands.kt +++ b/src/discord_api/kotlin/me/shedaniel/linkie/discord/scommands/SlashCommands.kt @@ -260,17 +260,15 @@ class SlashCommands( } } - fun ApplicationCommandInteractionOption.collectOptions(): MutableMap { - val map = mutableMapOf() + fun ApplicationCommandInteractionOption.collectOptions(map: MutableMap) { for (option in options) { if (!map.containsKey(option.name)) { if (option.value.isPresent) { map[option.name] = option.value.get().raw } - map.putAll(option.collectOptions()) + option.collectOptions(map) } } - return map } fun ChatInputInteractionEvent.collectOptions(): MutableMap { @@ -280,12 +278,12 @@ class SlashCommands( if (option.value.isPresent) { map[option.name] = option.value.get().raw } - map.putAll(option.collectOptions()) + option.collectOptions(map) } } return map } - + if (!rateLimiter.allow(event.user, cmd, event.collectOptions())) { val exception = RateLimitException(rateLimiter.maxRequestPer10Sec) if (throwableHandler.shouldError(exception)) { diff --git a/src/main/kotlin/me/shedaniel/linkie/discord/LinkieThrowableHandler.kt b/src/main/kotlin/me/shedaniel/linkie/discord/LinkieThrowableHandler.kt index 143e548..a9405c0 100644 --- a/src/main/kotlin/me/shedaniel/linkie/discord/LinkieThrowableHandler.kt +++ b/src/main/kotlin/me/shedaniel/linkie/discord/LinkieThrowableHandler.kt @@ -31,12 +31,12 @@ object LinkieThrowableHandler : SimpleThrowableHandler() { } when { throwable is org.graalvm.polyglot.PolyglotException -> { - val details = throwable.localizedMessage ?: "" + val details = throwable.localizedMessage?.take(800) ?: "" builder.fields(mutableListOf()) builder.addField("Error occurred while processing the command", "```$details```", false) } throwable.javaClass.name.startsWith("org.graalvm") -> { - val details = throwable.localizedMessage ?: "" + val details = throwable.localizedMessage?.take(800) ?: "" builder.fields(mutableListOf()) builder.addField("Error occurred while processing the command", "```" + throwable.javaClass.name + (if (details.isEmpty()) "" else ":\n") + details + "```", false) }