feat: make the bot save a stacktrace, if an error occurs during a command or interaction
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m55s

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2024-01-31 13:47:14 +01:00
parent 0f399cb58c
commit 906c41be88
Signed by: moonleay
GPG key ID: 82667543CCD715FB
2 changed files with 59 additions and 4 deletions

View file

@ -26,12 +26,15 @@ import dev.kord.core.event.interaction.ButtonInteractionCreateEvent
import dev.kord.core.on
import dev.kord.gateway.Intent
import dev.kord.gateway.PrivilegedIntent
import dev.kord.gateway.builder.Shards
import dev.kord.rest.builder.message.embed
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import net.moonleay.lilJudd.buttons.component.EditButtonManager
import net.moonleay.lilJudd.data.CredentialManager
import net.moonleay.lilJudd.data.StacktraceSaver
import net.moonleay.lilJudd.data.api.splatoon3ink.Splatoon3Api
import net.moonleay.lilJudd.data.database.DB
import net.moonleay.lilJudd.extensions.*
@ -125,11 +128,26 @@ object Bot {
+Intent.GuildMembers
}
// Will add Sharding someday, I promise
/*
sharding { recommended ->
errorResponse { _, type ->
val stamp = System.currentTimeMillis()
this.embed {
this.title = "Oops. Something went wrong."
this.description = "The bot encountered an error during execution.\n" +
"Please report this to <@${BuildConstants.ownerID}>.\n" +
"The errorid is \"$stamp.stk\""
this.field {
this.name = "Error message:"
this.value = type.error.message.toString()
this.inline = false
}
}
StacktraceSaver.saveStacktrace(type.error, stamp)
}
this.sharding { recommended ->
Shards(recommended)
} */
}
}
// Register button presses

View file

@ -0,0 +1,37 @@
/*
* lilJudd
* Copyright (C) 2024 moonleay
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data
import java.io.File
object StacktraceSaver {
fun saveStacktrace(stacktrace: Throwable, timestamp: Long) {
createFolder()
val dir = File("data", "stacktraces")
File(dir, "$timestamp.stk").bufferedWriter().use { out ->
out.write(stacktrace.stackTraceToString())
}
}
private fun createFolder() {
val dir = File("data", "stacktraces")
if (!dir.exists())
dir.mkdir()
}
}