Skip to content

Commit b5ba291

Browse files
authored
Rewrite Spring configuration metadata generator (#262)
1 parent 33840dc commit b5ba291

37 files changed

Lines changed: 515 additions & 357 deletions

File tree

BotCommands-core/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ plugins {
99
id("kotlin-conventions")
1010
id("publish-conventions")
1111
id("dokka-conventions")
12-
13-
alias(libs.plugins.ksp)
12+
id("spring-configuration-metadata-conventions")
1413
}
1514

1615
// Register other source sets
@@ -90,10 +89,6 @@ dependencies {
9089
compileOnly(libs.jetbrains.annotations)
9190
api(libs.jspecify)
9291

93-
// -------------------- ANNOTATION PROCESSORS --------------------
94-
95-
ksp(projects.springPropertiesProcessor)
96-
9792
// -------------------- DOC EXAMPLES DEPENDENCIES --------------------
9893

9994
// YAML (de)serialization

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ import io.github.freya022.botcommands.internal.core.config.ConfigurationValue
77

88
@InjectedService
99
interface BAppEmojisConfig : IConfig, BAppEmojisConfigProps {
10+
1011
override val configType get() = BAppEmojisConfig::class.java
1112
}
1213

1314
interface BAppEmojisConfigProps {
15+
1416
/**
1517
* Allows uploading application emojis at startup, and retrieving them from [AppEmojisRegistry].
1618
*
1719
* Default: `false`
1820
*
1921
* Spring property: `botcommands.app.emojis.enable`
2022
*/
21-
@ConfigurationValue(path = "botcommands.app.emojis.enable", defaultValue = "false")
23+
@get:ConfigurationValue(
24+
path = "botcommands.app.emojis.enable",
25+
description = "Allows uploading application emojis at startup, and retrieving them from [AppEmojisRegistry].",
26+
defaultValue = "false",
27+
)
2228
val enable: Boolean
2329

2430
/**
@@ -31,12 +37,17 @@ interface BAppEmojisConfigProps {
3137
*
3238
* Spring property: `botcommands.app.emojis.deleteOnOutOfSlots`
3339
*/
34-
@ConfigurationValue(path = "botcommands.app.emojis.deleteOnOutOfSlots", defaultValue = "false")
40+
@get:ConfigurationValue(
41+
path = "botcommands.app.emojis.deleteOnOutOfSlots",
42+
description = "Allows deleting application emojis that are not managed by this application, starting from the oldest. This keeps emojis by name, not by content.",
43+
defaultValue = "false",
44+
)
3545
val deleteOnOutOfSlots: Boolean
3646
}
3747

3848
@ConfigDSL
3949
class BAppEmojisConfigBuilder internal constructor() : BAppEmojisConfigProps {
50+
4051
@set:JvmName("enable")
4152
override var enable: Boolean = false
4253

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

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ import kotlin.io.path.Path
3030

3131
@InjectedService
3232
interface BApplicationConfig : IConfig, BApplicationConfigProps {
33+
3334
override val configType get() = BApplicationConfig::class.java
3435
}
3536

3637
interface BApplicationConfigProps {
38+
3739
/**
38-
* Whether application commands should be listened for.
40+
* Whether the application commands feature should be enabled.
3941
*
4042
* You can use [@RequiresApplicationCommands][RequiresApplicationCommands]
4143
* to disable services when this is set to `false`.
@@ -44,7 +46,11 @@ interface BApplicationConfigProps {
4446
*
4547
* Spring property: `botcommands.application.enable`
4648
*/
47-
@ConfigurationValue(path = "botcommands.application.enable", defaultValue = "true")
49+
@get:ConfigurationValue(
50+
path = "botcommands.application.enable",
51+
description = "Whether the application commands feature should be enabled.",
52+
defaultValue = "true",
53+
)
4854
val enable: Boolean
4955

5056
/**
@@ -54,17 +60,23 @@ interface BApplicationConfigProps {
5460
*
5561
* Spring property: `botcommands.application.guildsToUpdate`
5662
*/
57-
@ConfigurationValue(path = "botcommands.application.guildsToUpdate")
63+
@get:ConfigurationValue(
64+
path = "botcommands.application.guildsToUpdate",
65+
description = "If not empty, application commands will only be updated in these guilds. Existing commands won't be removed in other guilds, global commands will still be updated.",
66+
)
5867
val guildsToUpdate: List<Long>
5968

6069
/**
61-
* Test guilds IDs for all commands annotated with [Test]
70+
* Test guilds IDs for all commands annotated with [Test].
6271
*
6372
* Spring property: `botcommands.application.testGuildIds`
6473
*
6574
* @see Test @Test
6675
*/
67-
@ConfigurationValue(path = "botcommands.application.testGuildIds")
76+
@get:ConfigurationValue(
77+
path = "botcommands.application.testGuildIds",
78+
description = "Test guilds IDs for all commands annotated with [Test].",
79+
)
6880
val testGuildIds: List<Long>
6981

7082
/**
@@ -76,7 +88,11 @@ interface BApplicationConfigProps {
7688
*
7789
* Spring property: `botcommands.application.disableAutocompleteCache`
7890
*/
79-
@ConfigurationValue(path = "botcommands.application.disableAutocompleteCache", defaultValue = "false")
91+
@get:ConfigurationValue(
92+
path = "botcommands.application.disableAutocompleteCache",
93+
description = "Disables autocomplete caching, unless [CacheAutocomplete.forceCache] is set to `true`.",
94+
defaultValue = "false",
95+
)
8096
val disableAutocompleteCache: Boolean
8197

8298
/**
@@ -102,7 +118,11 @@ interface BApplicationConfigProps {
102118
*
103119
* Spring property: `botcommands.application.forceGuildCommands`
104120
*/
105-
@ConfigurationValue(path = "botcommands.application.forceGuildCommands", defaultValue = "false")
121+
@get:ConfigurationValue(
122+
path = "botcommands.application.forceGuildCommands",
123+
description = "Whether all application commands should be registered on each guild, regardless of the command scope on the annotation.",
124+
defaultValue = "false",
125+
)
106126
val forceGuildCommands: Boolean
107127

108128
/**
@@ -129,7 +149,10 @@ interface BApplicationConfigProps {
129149
* @see DefaultLocalizationMapProvider
130150
* @see JacksonLocalizationMapReader
131151
*/
132-
@ConfigurationValue(path = "botcommands.application.localizations")
152+
@get:ConfigurationValue(
153+
path = "botcommands.application.localizations",
154+
description = "Map where the key is the base bundle name, and the values are the supported locales, see the docs of [BApplicationConfigBuilder#addLocalization].",
155+
)
133156
val baseNameToLocalesMap: Map<String, List<DiscordLocale>>
134157

135158
/**
@@ -143,16 +166,22 @@ interface BApplicationConfigProps {
143166
*
144167
* Spring property: `botcommands.application.logMissingLocalizationKeys`
145168
*/
146-
@ConfigurationValue(path = "botcommands.application.logMissingLocalizationKeys", defaultValue = "false")
169+
@get:ConfigurationValue(
170+
path = "botcommands.application.logMissingLocalizationKeys",
171+
description = "Whether to log a `WARN` if a localization key isn't found when registering the commands.",
172+
defaultValue = "false",
173+
)
147174
val logMissingLocalizationKeys: Boolean
148175
}
149176

150177
@ConfigDSL
151178
class BApplicationConfigBuilder internal constructor() : BApplicationConfigProps {
179+
152180
@set:JvmName("enable")
153181
override var enable: Boolean = true
154182
override val guildsToUpdate: MutableList<Long> = mutableListOf()
155183
override val testGuildIds: MutableList<Long> = mutableListOf()
184+
156185
@set:DevConfig
157186
@set:JvmName("disableAutocompleteCache")
158187
override var disableAutocompleteCache = false

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
package io.github.freya022.botcommands.api.core.config
22

33
import io.github.freya022.botcommands.api.components.Buttons
4-
import io.github.freya022.botcommands.api.components.Components
54
import io.github.freya022.botcommands.api.components.SelectMenus
5+
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents
66
import io.github.freya022.botcommands.api.core.db.ConnectionSupplier
77
import io.github.freya022.botcommands.api.core.service.annotations.InjectedService
88
import io.github.freya022.botcommands.internal.core.config.ConfigDSL
99
import io.github.freya022.botcommands.internal.core.config.ConfigurationValue
1010

1111
@InjectedService
1212
interface BComponentsConfig : IConfig, BComponentsConfigProps {
13+
1314
override val configType get() = BComponentsConfig::class.java
1415
}
1516

1617
interface BComponentsConfigProps {
18+
1719
/**
18-
* Allows loading component services,
19-
* such as [Components], [Buttons] and [SelectMenus].
20+
* Whether the components feature should be enabled. Enabling this requires a [ConnectionSupplier] service.
2021
*
21-
* This requires a [ConnectionSupplier] service to be present
22+
* You can use [@RequiresComponents][RequiresComponents]
23+
* to disable services when this is set to `false`.
2224
*
2325
* Default: `false`
2426
*
2527
* Spring property: `botcommands.components.enable` ; Spring property takes over this config property.
2628
*
2729
* @see ConnectionSupplier
30+
* @see Buttons
31+
* @see SelectMenus
2832
*/
29-
@ConfigurationValue(path = "botcommands.components.enable", defaultValue = "false")
33+
@get:ConfigurationValue(
34+
path = "botcommands.components.enable",
35+
description = "Whether the components feature should be enabled. Enabling this requires a [ConnectionSupplier] service.",
36+
defaultValue = "false",
37+
)
3038
val enable: Boolean
3139
}
3240

3341
@ConfigDSL
3442
class BComponentsConfigBuilder internal constructor() : BComponentsConfigProps {
43+
3544
@set:JvmName("enable")
3645
override var enable: Boolean = false
3746

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

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import kotlin.reflect.KClass
2222

2323
@InjectedService
2424
interface BConfig : IConfig, BConfigProps {
25+
2526
override val configType get() = BConfig::class.java
2627

2728
val eventManagerConfig: BEventManagerConfig
@@ -49,6 +50,7 @@ interface BConfig : IConfig, BConfigProps {
4950
}
5051

5152
interface BConfigProps {
53+
5254
/**
5355
* Predefined user IDs of the bot owners, allowing bypassing cooldowns, user permission checks,
5456
* and having [hidden commands][Hidden] shown.
@@ -59,32 +61,47 @@ interface BConfigProps {
5961
*
6062
* Spring property: `botcommands.core.predefinedOwnerIds`
6163
*/
62-
@ConfigurationValue(path = "botcommands.core.predefinedOwnerIds")
64+
@get:ConfigurationValue(
65+
path = "botcommands.core.predefinedOwnerIds",
66+
description = "Predefined user IDs of the bot owners, allowing bypassing cooldowns, user permission checks, and having [Hidden] commands shown. See the documentation for more details.",
67+
)
6368
val predefinedOwnerIds: Set<Long>
6469

6570
/**
6671
* The packages the framework will scan through for services, commands, handlers...
6772
*
6873
* Spring property: `botcommands.core.packages`
6974
*/
70-
@ConfigurationValue(path = "botcommands.core.packages")
75+
@get:ConfigurationValue(
76+
path = "botcommands.core.packages",
77+
description = "The packages the framework will scan through for services, commands, handlers...",
78+
)
7179
val packages: Set<String>
80+
7281
/**
7382
* Additional classes the framework will scan through for services, commands, handlers...
7483
*
7584
* Spring property: `botcommands.core.classes`
7685
*/
77-
@ConfigurationValue(path = "botcommands.core.classes", type = "java.util.Set<java.lang.Class<?>>")
86+
@get:ConfigurationValue(
87+
path = "botcommands.core.classes",
88+
description = "Additional classes the framework will scan through for services, commands, handlers...",
89+
type = "java.util.Set<java.lang.Class<?>>",
90+
)
7891
val classes: Set<Class<*>>
7992

8093
/**
81-
* Disables sending exceptions to the bot owners
94+
* Disables sending exceptions to the bot owners.
8295
*
8396
* Default: `false`
8497
*
8598
* Spring property: `botcommands.core.disableExceptionsInDMs`
8699
*/
87-
@ConfigurationValue(path = "botcommands.core.disableExceptionsInDMs", defaultValue = "false")
100+
@get:ConfigurationValue(
101+
path = "botcommands.core.disableExceptionsInDMs",
102+
description = "Disables sending exceptions to the bot owners.",
103+
defaultValue = "false",
104+
)
88105
val disableExceptionsInDMs: Boolean
89106

90107
/**
@@ -96,17 +113,24 @@ interface BConfigProps {
96113
*
97114
* @see BotOwners
98115
*/
99-
@ConfigurationValue(path = "botcommands.core.enableOwnerBypass", defaultValue = "false")
116+
@get:ConfigurationValue(
117+
path = "botcommands.core.enableOwnerBypass",
118+
description = "Enables *bot* owners to bypass certain limits.",
119+
defaultValue = "false",
120+
)
100121
val enableOwnerBypass: Boolean
101122

102123
/**
103-
* Gateway intents to ignore when checking for [event listeners][BEventListener] intents.
124+
* Gateway intents to ignore when checking for required intents of [event listeners][BEventListener].
104125
*
105126
* Spring property: `botcommands.core.ignoredIntents`
106127
*
107128
* @see BEventListener.ignoreIntents
108129
*/
109-
@ConfigurationValue(path = "botcommands.core.ignoredIntents")
130+
@get:ConfigurationValue(
131+
path = "botcommands.core.ignoredIntents",
132+
description = "Gateway intents to ignore when checking for required intents of event listeners.",
133+
)
110134
val ignoredIntents: Set<GatewayIntent>
111135

112136
/**
@@ -118,7 +142,11 @@ interface BConfigProps {
118142
*
119143
* @see PriorityGlobalRestRateLimiter
120144
*/
121-
@ConfigurationValue("botcommands.core.ignoreRestRateLimiter", defaultValue = "false")
145+
@get:ConfigurationValue(
146+
path = "botcommands.core.ignoreRestRateLimiter",
147+
description = "Suppresses warnings about the default [RestRateLimiter] being used for large bots.",
148+
defaultValue = "false",
149+
)
122150
val ignoreRestRateLimiter: Boolean
123151

124152
val classGraphProcessors: List<ClassGraphProcessor>
@@ -132,7 +160,11 @@ interface BConfigProps {
132160
*
133161
* Spring property: `botcommands.core.enableShutdownHook`
134162
*/
135-
@ConfigurationValue("botcommands.core.enableShutdownHook", defaultValue = "true")
163+
@get:ConfigurationValue(
164+
path = "botcommands.core.enableShutdownHook",
165+
description = "Whether to use a shutdown hook to call [BContext.shutdownNow] when the JVM is exiting **gracefully**.",
166+
defaultValue = "true",
167+
)
136168
val enableShutdownHook: Boolean
137169
}
138170

@@ -152,13 +184,15 @@ inline fun <reified T : IConfig> BConfig.getConfigOrNull(): T? = getConfigOrNull
152184

153185
@ConfigDSL
154186
class BConfigBuilder : BConfigProps {
187+
155188
override val packages: MutableSet<String> = HashSet()
156189
override val classes: MutableSet<Class<*>> = HashSet()
157190

158191
override val predefinedOwnerIds: MutableSet<Long> = HashSet()
159192

160193
@set:JvmName("disableExceptionsInDMs")
161194
override var disableExceptionsInDMs = false
195+
162196
@set:JvmName("enableOwnerBypass")
163197
override var enableOwnerBypass = false
164198

0 commit comments

Comments
 (0)