Skip to content

Commit

Permalink
Refactor HoconUtils, InteractionEventListener and ProfileUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
WinG4merBR committed Jan 6, 2025
1 parent 6435944 commit ed58ffe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter
import kotlin.reflect.jvm.jvmName
import kotlin.system.measureTimeMillis

class InteractionEventListener(
private val foxy: FoxyInstance
Expand Down Expand Up @@ -56,11 +57,14 @@ class InteractionEventListener(
}

try {
if (subCommand != null) {
subCommand.executor?.execute(context)
} else if (subCommandGroupName == null && subCommandName == null) {
command.executor?.execute(context)
val executionTime = measureTimeMillis {
if (subCommand != null) {
subCommand.executor?.execute(context)
} else if (subCommandGroupName == null && subCommandName == null) {
command.executor?.execute(context)
}
}
logger.info { "Command /${event.fullCommandName} executed in ${executionTime}ms" }
} catch (e: Exception) {
logger.error(e) { "An error occurred while executing command: ${event.fullCommandName}" }
context.reply(true) {
Expand Down Expand Up @@ -106,7 +110,7 @@ class InteractionEventListener(
}
}
}

override fun onStringSelectInteraction(event: StringSelectInteractionEvent) {
coroutineScope.launch {
val componentId = try {
Expand Down
3 changes: 2 additions & 1 deletion foxy/src/main/kotlin/net/cakeyfox/foxy/utils/HoconUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import kotlinx.serialization.hocon.decodeFromConfig

object HoconUtils {
@OptIn(ExperimentalSerializationApi::class)
inline fun <reified T> Hocon.decodeFromString(string: String): T = decodeFromConfig(ConfigFactory.parseString(string).resolve())
inline fun <reified T> Hocon.decodeFromString(string: String): T =
decodeFromConfig(ConfigFactory.parseString(string).resolve())
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ object ProfileUtils {
fun formatAboutMe(aboutMe: String, layoutInfo: Layout): String {
val aboutMeLimit = layoutInfo.profileSettings.aboutme.limit
val breakLength = layoutInfo.profileSettings.aboutme.breakLength

return if (aboutMe.length > aboutMeLimit) {
aboutMe.chunked(breakLength).joinToString("\n")
} else {
Expand Down

0 comments on commit ed58ffe

Please sign in to comment.