Skip to content

Commit cdfc636

Browse files
committed
app commands: Renamed slashGuildIds property to guildsToUpdate
1 parent 6baa9cf commit cdfc636

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/api/core/config/BApplicationConfig.kt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import io.github.freya022.botcommands.api.localization.readers.JacksonLocalizati
1919
import io.github.freya022.botcommands.api.localization.readers.LocalizationMapReader
2020
import io.github.freya022.botcommands.internal.core.config.ConfigDSL
2121
import io.github.freya022.botcommands.internal.core.config.ConfigurationValue
22+
import io.github.freya022.botcommands.internal.core.config.DeprecatedValue
2223
import io.github.freya022.botcommands.internal.core.exceptions.internalErrorMessage
2324
import io.github.freya022.botcommands.internal.utils.lazyWritable
2425
import io.github.freya022.botcommands.internal.utils.throwInternal
@@ -50,8 +51,20 @@ interface BApplicationConfig {
5051
*
5152
* Spring property: `botcommands.application.slashGuildIds`
5253
*/
54+
@Deprecated("Replaced by 'guildsToUpdate'", replaceWith = ReplaceWith("guildToUpdate"))
55+
@DeprecatedValue("Replaced by 'guildsToUpdate'", replacement = "botcommands.application.slashGuildIds")
5356
@ConfigurationValue(path = "botcommands.application.slashGuildIds")
54-
val slashGuildIds: List<Long>
57+
val slashGuildIds: List<Long> get() = guildsToUpdate
58+
59+
/**
60+
* If not empty, application commands will only be updated in these guilds.
61+
*
62+
* Existing commands won't be removed in other guilds, global commands will still be updated.
63+
*
64+
* Spring property: `botcommands.application.guildsToUpdate`
65+
*/
66+
@ConfigurationValue(path = "botcommands.application.guildsToUpdate")
67+
val guildsToUpdate: List<Long>
5568

5669
/**
5770
* Test guilds IDs for all commands annotated with [Test]
@@ -147,7 +160,9 @@ interface BApplicationConfig {
147160
class BApplicationConfigBuilder internal constructor() : BApplicationConfig {
148161
@set:JvmName("enable")
149162
override var enable: Boolean = true
150-
override val slashGuildIds: MutableList<Long> = mutableListOf()
163+
@Deprecated("Replaced by 'guildsToUpdate'", replaceWith = ReplaceWith("guildToUpdate"))
164+
override val slashGuildIds: MutableList<Long> get() = guildsToUpdate
165+
override val guildsToUpdate: MutableList<Long> = mutableListOf()
151166
override val testGuildIds: MutableList<Long> = mutableListOf()
152167
@set:DevConfig
153168
@set:JvmName("disableAutocompleteCache")
@@ -345,7 +360,7 @@ class BApplicationConfigBuilder internal constructor() : BApplicationConfig {
345360

346361
return object : BApplicationConfig {
347362
override val enable = this@BApplicationConfigBuilder.enable
348-
override val slashGuildIds = this@BApplicationConfigBuilder.slashGuildIds.toImmutableList()
363+
override val guildsToUpdate = this@BApplicationConfigBuilder.guildsToUpdate.toImmutableList()
349364
override val testGuildIds = this@BApplicationConfigBuilder.testGuildIds.toImmutableList()
350365
override val disableAutocompleteCache = this@BApplicationConfigBuilder.disableAutocompleteCache
351366
override val cache = this@BApplicationConfigBuilder.cache?.build()
@@ -356,4 +371,4 @@ class BApplicationConfigBuilder internal constructor() : BApplicationConfig {
356371
override val logMissingLocalizationKeys = this@BApplicationConfigBuilder.logMissingLocalizationKeys
357372
}
358373
}
359-
}
374+
}

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/commands/application/ApplicationCommandsBuilder.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ internal class ApplicationCommandsBuilder(
109109
}
110110

111111
internal suspend fun updateGuildCommands(guild: Guild, force: Boolean = false): CommandUpdateResult {
112-
val slashGuildIds = context.applicationConfig.slashGuildIds
113-
if (slashGuildIds.isNotEmpty()) {
114-
if (guild.idLong !in slashGuildIds) {
115-
logger.trace { "Skipping application command updates in ${guild.name} (${guild.id}) as it is not in ${BApplicationConfig::slashGuildIds.reference}" }
112+
val guildsToUpdate = context.applicationConfig.guildsToUpdate
113+
if (guildsToUpdate.isNotEmpty()) {
114+
if (guild.idLong !in guildsToUpdate) {
115+
logger.trace { "Skipping application command updates in ${guild.name} (${guild.id}) as it is not in ${BApplicationConfig::guildsToUpdate.reference}" }
116116
firstGuildUpdates.add(guild.idLong)
117117
return CommandUpdateResult(guild, false, listOf())
118118
}
@@ -207,4 +207,4 @@ internal class ApplicationCommandsBuilder(
207207
logger.error(it) { "Errors occurred while registering global commands" }
208208
}
209209
}
210-
}
210+
}

BotCommands-spring/src/main/kotlin/io/github/freya022/botcommands/internal/core/config/BotCommandsConfigurations.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ internal fun BLocalizationConfigBuilder.applyConfig(configuration: BotCommandsLo
128128
@ConfigurationProperties(prefix = "botcommands.application", ignoreUnknownFields = true)
129129
internal class BotCommandsApplicationConfiguration(
130130
override val enable: Boolean = true,
131-
override val slashGuildIds: List<Long> = emptyList(),
131+
slashGuildIds: List<Long> = emptyList(),
132+
guildsToUpdate: List<Long> = emptyList(),
132133
override val testGuildIds: List<Long> = emptyList(),
133134
override val disableAutocompleteCache: Boolean = false,
134135
override val forceGuildCommands: Boolean = false,
@@ -139,6 +140,11 @@ internal class BotCommandsApplicationConfiguration(
139140
) : BApplicationConfig {
140141
override val cache: Nothing get() = unusable()
141142

143+
override val guildsToUpdate: List<Long> = when {
144+
guildsToUpdate.isNotEmpty() -> guildsToUpdate
145+
else -> slashGuildIds
146+
}
147+
142148
class Cache(
143149
/**
144150
* Type of application commands cache.
@@ -179,7 +185,7 @@ internal class BotCommandsApplicationConfiguration(
179185
@OptIn(DevConfig::class)
180186
internal fun BApplicationConfigBuilder.applyConfig(configuration: BotCommandsApplicationConfiguration) = apply {
181187
enable = configuration.enable
182-
slashGuildIds += configuration.slashGuildIds
188+
guildsToUpdate += configuration.guildsToUpdate
183189
testGuildIds += configuration.testGuildIds
184190
disableAutocompleteCache = configuration.disableAutocompleteCache
185191
configureCache(configuration)

0 commit comments

Comments
 (0)