-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigReloadCommand.kt
More file actions
47 lines (43 loc) · 1.96 KB
/
Copy pathConfigReloadCommand.kt
File metadata and controls
47 lines (43 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package es.wokis.commands.config
import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior
import dev.kord.core.behavior.interaction.response.respond
import dev.kord.core.entity.interaction.ChatInputCommandInteraction
import dev.kord.rest.builder.interaction.GlobalChatInputCreateBuilder
import dev.kord.rest.builder.interaction.subCommand
import es.wokis.commands.CommandName
import es.wokis.commands.SubCommand
import es.wokis.localization.LocalizationKeys
import es.wokis.services.config.ConfigService
import es.wokis.services.localization.LocalizationService
import es.wokis.utils.Log
import es.wokis.utils.orDefaultLocale
class ConfigReloadCommand(
private val configService: ConfigService,
private val localizationService: LocalizationService
) : SubCommand {
override suspend fun onRegisterCommand(builder: GlobalChatInputCreateBuilder) {
builder.apply {
subCommand(CommandName.Config.Reload.commandName, localizationService.getString(LocalizationKeys.CONFIG_RELOAD_COMMAND_DESCRIPTION)) {
descriptionLocalizations = localizationService.getLocalizations(LocalizationKeys.CONFIG_RELOAD_COMMAND_DESCRIPTION)
}
}
}
override suspend fun onExecute(
interaction: ChatInputCommandInteraction,
response: DeferredPublicMessageInteractionResponseBehavior
) {
val locale = interaction.guildLocale.orDefaultLocale()
try {
configService.reload()
Log.info("Configuration reloaded via command by user ${interaction.user.id}")
response.respond {
content = localizationService.getString(LocalizationKeys.CONFIG_RELOAD_SUCCESS, locale)
}
} catch (e: Exception) {
Log.error("Failed to reload config via command", e)
response.respond {
content = localizationService.getString(LocalizationKeys.ERROR_UNEXPECTED, locale)
}
}
}
}