Skip to content

Commit

Permalink
Try to limit
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <daniel@shedaniel.me>
  • Loading branch information
shedaniel committed Jun 7, 2022
1 parent c5784be commit e56b7f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,15 @@ class SlashCommands(
}
}

fun ApplicationCommandInteractionOption.collectOptions(): MutableMap<String, Any> {
val map = mutableMapOf<String, Any>()
fun ApplicationCommandInteractionOption.collectOptions(map: MutableMap<String, Any>) {
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<String, Any> {
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit e56b7f5

Please sign in to comment.