This should allow metrics to see subcommand usage

This commit is contained in:
NovaFox161
2024-03-17 20:08:14 -05:00
parent a89a268725
commit fbd60eb999
15 changed files with 21 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ import reactor.core.publisher.Mono
interface SlashCommand {
val name: String
val hasSubcommands: Boolean
val ephemeral: Boolean
@Deprecated("Use new handleSuspend for K-coroutines")

View File

@@ -1,16 +1,16 @@
package org.dreamexposure.discal.client.commands.dev
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
import discord4j.core.`object`.entity.Message
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
import org.dreamexposure.discal.client.commands.SlashCommand
import org.dreamexposure.discal.core.`object`.GuildSettings
import org.dreamexposure.discal.core.`object`.web.UserAPIAccount
import org.dreamexposure.discal.core.crypto.KeyGenerator.csRandomAlphaNumericString
import org.dreamexposure.discal.core.database.DatabaseManager
import org.dreamexposure.discal.core.extensions.discord4j.followupEphemeral
import org.dreamexposure.discal.core.logger.LOGGER
import org.dreamexposure.discal.core.`object`.GuildSettings
import org.dreamexposure.discal.core.`object`.web.UserAPIAccount
import org.dreamexposure.discal.core.utils.GlobalVal
import org.springframework.stereotype.Component
import reactor.core.publisher.Mono
@@ -18,6 +18,7 @@ import reactor.core.publisher.Mono
@Component
class DevCommand : SlashCommand {
override val name = "dev"
override val hasSubcommands = true
override val ephemeral = true
@Deprecated("Use new handleSuspend for K-coroutines")

View File

@@ -29,6 +29,7 @@ class AnnouncementCommand(
private val embedService: EmbedService,
) : SlashCommand {
override val name = "announcement"
override val hasSubcommands = true
override val ephemeral = true
override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message {

View File

@@ -30,6 +30,7 @@ class CalendarCommand(
private val staticMessageService: StaticMessageService
) : SlashCommand {
override val name = "calendar"
override val hasSubcommands = true
override val ephemeral = true
@Deprecated("Use new handleSuspend for K-coroutines")

View File

@@ -18,6 +18,7 @@ class DiscalCommand(
private val embedService: EmbedService,
) : SlashCommand {
override val name = "discal"
override val hasSubcommands = false
override val ephemeral = false
override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message {

View File

@@ -20,6 +20,7 @@ class DisplayCalendarCommand(
private val staticMessageService: StaticMessageService,
) : SlashCommand {
override val name = "displaycal"
override val hasSubcommands = true
override val ephemeral = true

View File

@@ -36,6 +36,7 @@ class EventCommand(
private val staticMessageService: StaticMessageService
) : SlashCommand {
override val name = "event"
override val hasSubcommands = true
override val ephemeral = true
@Deprecated("Use new handleSuspend for K-coroutines")

View File

@@ -23,6 +23,7 @@ import java.time.format.DateTimeParseException
@Component
class EventsCommand : SlashCommand {
override val name = "events"
override val hasSubcommands = true
override val ephemeral = false
@Deprecated("Use new handleSuspend for K-coroutines")

View File

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component
@Component
class HelpCommand : SlashCommand {
override val name = "help"
override val hasSubcommands = false
override val ephemeral = true
override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message {

View File

@@ -19,6 +19,7 @@ class LinkCalendarCommand(
private val embedService: EmbedService,
) : SlashCommand {
override val name = "linkcal"
override val hasSubcommands = false
override val ephemeral = false

View File

@@ -24,6 +24,7 @@ class RsvpCommand(
private val embedService: EmbedService,
) : SlashCommand {
override val name = "rsvp"
override val hasSubcommands = true
override val ephemeral = true

View File

@@ -20,6 +20,7 @@ import reactor.core.publisher.Mono
@Component
class SettingsCommand : SlashCommand {
override val name = "settings"
override val hasSubcommands = true
override val ephemeral = true
@Deprecated("Use new handleSuspend for K-coroutines")

View File

@@ -19,6 +19,7 @@ class TimeCommand(
private val embedService: EmbedService,
) : SlashCommand {
override val name = "time"
override val hasSubcommands = false
override val ephemeral = true
override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message {

View File

@@ -17,6 +17,7 @@ import reactor.core.publisher.Mono
@Component
class AddCalCommand : SlashCommand {
override val name = "addcal"
override val hasSubcommands = false
override val ephemeral = true
@Deprecated("Use new handleSuspend for K-coroutines")

View File

@@ -29,6 +29,7 @@ class SlashCommandListener(
}
val command = commands.firstOrNull { it.name == event.commandName }
val subCommand = if (command?.hasSubcommands == true) event.options[0].name else null
if (command != null) {
event.deferReply().withEphemeral(command.ephemeral).awaitSingleOrNull()
@@ -52,6 +53,8 @@ class SlashCommandListener(
}
timer.stop()
metricService.recordInteractionDuration(event.commandName, "chat-input", timer.totalTimeMillis)
val computedInteractionName = if (subCommand != null) "/${event.commandName}#$subCommand" else "/${event.commandName}"
metricService.recordInteractionDuration(computedInteractionName, "chat-input", timer.totalTimeMillis)
}
}