Skip to content

Commit

Permalink
This should allow metrics to see subcommand usage
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Mar 18, 2024
1 parent a89a268 commit fbd60eb
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 5 deletions.
Expand Up @@ -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")
Expand Down
@@ -1,23 +1,24 @@
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

@Component
class DevCommand : SlashCommand {
override val name = "dev"
override val hasSubcommands = true
override val ephemeral = true

@Deprecated("Use new handleSuspend for K-coroutines")
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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")
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -20,6 +20,7 @@ class DisplayCalendarCommand(
private val staticMessageService: StaticMessageService,
) : SlashCommand {
override val name = "displaycal"
override val hasSubcommands = true
override val ephemeral = true


Expand Down
Expand Up @@ -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")
Expand Down
Expand Up @@ -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")
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -19,6 +19,7 @@ class LinkCalendarCommand(
private val embedService: EmbedService,
) : SlashCommand {
override val name = "linkcal"
override val hasSubcommands = false
override val ephemeral = false


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


Expand Down
Expand Up @@ -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")
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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")
Expand Down
Expand Up @@ -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()
Expand All @@ -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)
}
}

0 comments on commit fbd60eb

Please sign in to comment.