Skip to content

Commit

Permalink
Add ability for dev command to show guild settings for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Apr 12, 2024
1 parent ef82fd2 commit 8642f5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Expand Up @@ -7,6 +7,7 @@ import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
import discord4j.core.`object`.entity.Message
import kotlinx.coroutines.reactor.awaitSingle
import org.dreamexposure.discal.client.commands.SlashCommand
import org.dreamexposure.discal.core.business.EmbedService
import org.dreamexposure.discal.core.business.GuildSettingsService
import org.dreamexposure.discal.core.`object`.new.GuildSettings
import org.dreamexposure.discal.core.utils.GlobalVal
Expand All @@ -15,6 +16,7 @@ import org.springframework.stereotype.Component
@Component
class DevCommand(
private val settingsService: GuildSettingsService,
private val embedService: EmbedService,
) : SlashCommand {
override val name = "dev"
override val hasSubcommands = true
Expand All @@ -31,6 +33,7 @@ class DevCommand(
"patron" -> patron(event, settings)
"dev" -> dev(event, settings)
"maxcal" -> maxCalendars(event, settings)
"settings" -> settings(event)
else -> throw IllegalStateException("Invalid subcommand specified")
}
}
Expand Down Expand Up @@ -84,4 +87,19 @@ class DevCommand(
.withEphemeral(ephemeral)
.awaitSingle()
}

private suspend fun settings(event: ChatInputInteractionEvent): Message {
val guildId = event.options[0].getOption("guild")
.flatMap(ApplicationCommandInteractionOption::getValue)
.map(ApplicationCommandInteractionOptionValue::asString)
.map(Snowflake::of)
.get()

val targetSettings = settingsService.getSettings(guildId)

return event.createFollowup()
.withEmbeds(embedService.settingsEmbeds(targetSettings))
.withEphemeral(ephemeral)
.awaitSingle()
}
}
13 changes: 13 additions & 0 deletions core/src/main/resources/commands/dev/dev.json
Expand Up @@ -49,6 +49,19 @@
"required": true
}
]
},
{
"name": "settings",
"type": 1,
"description": "Allows viewing another guild's settings for debugging",
"options": [
{
"name": "guild",
"type": 3,
"description": "The ID of the guild to view",
"required": true
}
]
}
],
"default_permissions": true
Expand Down

0 comments on commit 8642f5e

Please sign in to comment.