Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions .github/workflows/check-kdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,46 @@ on:
pull_request:
branches:
- 3.X
paths:
- 'pom.xml'
- 'src/main/**.java'
- 'src/test/**.java'
- 'src/main/**.kt'
- 'src/test/**.kt'
push:
branches:
- 3.X
paths:
- 'pom.xml'
- 'src/main/**.java'
- 'src/test/**.java'
- 'src/main/**.kt'
- 'src/test/**.kt'

jobs:
check-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17

- name: Set up JDK 24
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Compile and run tests with Maven
run: mvn -B --file pom.xml -Dkotlin.compiler.incremental=false test
# Toolchain is 24 due to certain modules, but we compile down to 17 for most modules
java-version: '24'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Run tests
run: ./gradlew test
check-kdocs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17

- name: Set up JDK 24
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Build KDocs with Maven
run: mvn -P docs -B generate-sources dokka:dokka
# Toolchain is 24 due to certain modules, but we compile down to 17 for most modules
java-version: '24'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Build KDocs
run: ./gradlew dokkaGenerate
25 changes: 14 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ name: Deploy KDocs to Pages
on:
push:
branches: ["3.X"]
paths:
- 'pom.xml'
- 'src/main/**.java'
- 'src/main/**.kt'
workflow_dispatch:

# Allow one concurrent deployment
Expand All @@ -21,20 +17,27 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17

- name: Set up JDK 24
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Set release version
run: mvn -B BotCommandsBuild:set-ci-version
# Toolchain is 24 due to certain modules, but we compile down to 17 for most modules
java-version: '24'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Generate KDocs
run: mvn -B -P docs generate-sources dokka:dokka
run: ./gradlew dokkaGenerate

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./target/dokka
path: ./build/dokka

publish-docs:
name: Publish docs
runs-on: ubuntu-latest
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/jitpack-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ on:
- reopened
- synchronize
- closed
paths:
- 'pom.xml'
- 'src/main/**.java'
- 'src/test/**.java'
- 'src/main/**.kt'
- 'src/test/**.kt'

permissions:
pull-requests: write
Expand Down
36 changes: 16 additions & 20 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-Apache-Maven

name: Publish to Maven Central
on:
release:
Expand All @@ -11,30 +9,28 @@ jobs:
if: github.event.release.draft == false
steps:
- uses: actions/checkout@v4

- name: Configure Git User
run: |
git config user.email "41875020+freya022@users.noreply.github.com"
git config user.name "freya022"
- name: Set up JDK 17

- name: Set up JDK 24
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Set release version
run: mvn -B --file pom.xml BotCommandsBuild:set-ci-version
# Toolchain is 24 due to certain modules, but we compile down to 17 for most modules
java-version: '24'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Compile and release
run: >
mvn -B --file pom.xml
-P docs,release
-Dkotlin.compiler.incremental=false
deploy
run: ./gradlew publishToMavenCentral
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
ORG_GRADLE_PROJECT_mavenGpgSecretKey: ${{ secrets.GPG_SECRET_KEY }}
ORG_GRADLE_PROJECT_mavenGpgKeyId: ${{ secrets.GPG_KEY_ID }}
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

*.iml
.idea
target
release.properties
pom.xml.releaseBackup
build
.gradle
.kotlin

schemas/Test.json
/schemas
dev-config
dev-data
Binary file removed .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
18 changes: 0 additions & 18 deletions .mvn/wrapper/maven-wrapper.properties

This file was deleted.

41 changes: 41 additions & 0 deletions BotCommands-spring/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id("BotCommands-conventions")
id("BotCommands-publish-conventions")
alias(libs.plugins.ksp)
}

dependencies {
api(projects.botCommands)

// Logging
implementation(libs.kotlin.logging.jvm)

// -------------------- SPRING DEPENDENCIES --------------------

// Spring Boot
api(libs.spring.boot)
api(libs.spring.boot.autoconfigure)

// -------------------- ANNOTATION PROCESSORS --------------------

ksp(projects.springPropertiesProcessor)

// -------------------- TEST DEPENDENCIES --------------------

// Take the same test dependencies as the main library
testImplementation(rootProject.sourceSets.test.get().compileClasspath)
// Take the same test sources as the main library
testImplementation(rootProject.sourceSets.test.get().output)

// Spring Boot
testImplementation(libs.spring.boot.starter)
testRuntimeOnly(libs.spring.boot.devtools)
}

kotlin {
compilerOptions {
freeCompilerArgs.addAll(
"-Xjvm-default=all",
)
}
}
Original file line number Diff line number Diff line change
@@ -1,71 +1,53 @@
package io.github.freya022.botcommands.api.core.config

/**
* Base interface for runtime configuration, only usable with Spring, see sub-interfaces.
* Base interface for runtime configuration, see sub-interfaces.
*/
sealed interface BConfigurer<T : Any> {
fun configure(builder: T)
}

/**
* Configurer for [BConfig].
*
* Only usable with Spring.
*/
interface BConfigConfigurer : BConfigurer<BConfigBuilder>

/**
* Configurer for [BDatabaseConfig].
*
* Only usable with Spring.
*/
interface BDatabaseConfigConfigurer : BConfigurer<BDatabaseConfigBuilder>

/**
* Configurer for [BLocalizationConfig].
*
* Only usable with Spring.
*/
interface BLocalizationConfigConfigurer : BConfigurer<BLocalizationConfigBuilder>

/**
* Configurer for [BAppEmojisConfig].
*
* Only usable with Spring.
*/
interface BAppEmojisConfigConfigurer : BConfigurer<BAppEmojisConfigBuilder>

/**
* Configurer for [BTextConfig].
*
* Only usable with Spring.
*/
interface BTextConfigConfigurer : BConfigurer<BTextConfigBuilder>

/**
* Configurer for [BApplicationConfig].
*
* Only usable with Spring.
*/
interface BApplicationConfigConfigurer : BConfigurer<BApplicationConfigBuilder>

/**
* Configurer for [BModalsConfig].
*
* Only usable with Spring.
*/
interface BModalsConfigConfigurer : BConfigurer<BModalsConfigBuilder>

/**
* Configurer for [BComponentsConfig].
*
* Only usable with Spring.
*/
interface BComponentsConfigConfigurer : BConfigurer<BComponentsConfigBuilder>

/**
* Configurer for [BCoroutineScopesConfig].
*
* Only usable with Spring.
*/
interface BCoroutineScopesConfigConfigurer : BConfigurer<BCoroutineScopesConfigBuilder>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("ConfigurationProperties")

package io.github.freya022.botcommands.api.core.config

import io.github.freya022.botcommands.api.core.JDAService
Expand All @@ -10,9 +8,9 @@ import net.dv8tion.jda.api.utils.cache.CacheFlag
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.bind.Name
import org.springframework.context.event.ContextClosedEvent
import java.time.Duration as JavaDuration
import kotlin.time.Duration
import kotlin.time.toKotlinDuration
import java.time.Duration as JavaDuration

/**
* Configuration properties for [JDAService].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.freya022.botcommands.internal.core

import io.github.freya022.botcommands.api.core.JDAService
import io.github.freya022.botcommands.api.core.annotations.BEventListener
import io.github.freya022.botcommands.api.core.config.JDAConfiguration
import io.github.freya022.botcommands.api.core.events.InjectedJDAEvent
import io.github.freya022.botcommands.internal.utils.reference
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.stereotype.Component

private val logger = KotlinLogging.logger { }

// Spring checks are slightly different, we want to tell the user to move them to their application environment,
// so the checks are consistent with condition annotations, as they can only check the environment
@Component
internal class SpringJDAServiceMismatchChecker {
@BEventListener
internal fun onJDA(event: InjectedJDAEvent, jdaConfiguration: JDAConfiguration, jdaService: JDAService) {
val environmentIntents = jdaConfiguration.intents
val jdaServiceIntents = jdaService.intents
if (environmentIntents != jdaServiceIntents) {
logger.warn {
"""
The intents given in JDAService and the environment should be the same!
Environment intents: ${environmentIntents.sorted()}
JDAService intents: ${jdaServiceIntents.sorted()}
Hint: you should get your intents from ${JDAConfiguration::intents.reference}
""".trimIndent()
}
}

val environmentCacheFlags = jdaConfiguration.cacheFlags
val jdaServiceCacheFlags = jdaService.cacheFlags
if (environmentCacheFlags != jdaServiceCacheFlags) {
logger.warn {
"""
The cache flags given in JDAService and the environment should be the same!
Environment cache flags: ${environmentCacheFlags.sorted()}
JDAService cache flags: ${jdaServiceCacheFlags.sorted()}
Hint: you should get your caches flags from ${JDAConfiguration::cacheFlags.reference}
""".trimIndent()
}
}
}
}
Loading