feat: initial commit
All checks were successful
Release / release (push) Successful in 20s

This commit is contained in:
lucasdpt
2025-11-02 21:02:40 +01:00
commit bab2767aa5
9 changed files with 320 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
name: Release
on:
push:
branches:
- master
permissions:
contents: write
issues: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
container: git.tools.ldpt.fr/actions/ci-image:1.0.0
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Maven settings.xml
env:
MAVEN_SETTINGS: ${{ secrets.MAVEN_SETTINGS }}
run: |
mkdir -p .m2
echo "$MAVEN_SETTINGS" > .m2/settings.xml
- name: Release with semantic-release
run: |
npx semantic-release

33
.gitignore vendored Normal file
View File

@@ -0,0 +1,33 @@
HELP.md
target/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

23
.releaserc.json Normal file
View File

@@ -0,0 +1,23 @@
{
"branches": ["master"],
"tagFormat": "${version}",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/exec",
{
"prepareCmd": "mvn versions:set -DnewVersion=${nextRelease.version} -DgenerateBackupPoms=false",
"publishCmd": "mvn clean deploy --settings .m2/settings.xml"
}
],
[
"@semantic-release/git",
{
"assets": ["pom.xml", "CHANGELOG.md"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}

85
pom.xml Normal file
View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>fr.lucasdupont</groupId>
<artifactId>spring-jda-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-jda-starter</name>
<description>Starter for JDA project</description>
<properties>
<java.version>21</java.version>
<kotlin.version>2.2.0</kotlin.version>
<jda.version>6.1.1</jda.version>
</properties>
<distributionManagement>
<repository>
<id>gitea</id>
<url>https://git.tools.ldpt.fr/api/packages/galaxies/maven</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>${jda.version}</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,31 @@
package fr.lucasdupont.gaytabot.command
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions
import net.dv8tion.jda.api.interactions.commands.build.OptionData
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData
interface Command {
val name: String
val description: String
val options: List<OptionData>
get() = emptyList()
val neededPermissions: DefaultMemberPermissions?
get() = null
val subcommands: List<Command>
get() = emptyList()
val subcommandGroups: List<SubCommandGroup>
get() = emptyList()
@Throws(Exception::class)
fun execute(event: SlashCommandInteractionEvent)
fun toSubcommandData(): SubcommandData =
SubcommandData(name, description).addOptions(options)
}

View File

@@ -0,0 +1,23 @@
package fr.lucasdupont.gaytabot.command
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData
import net.dv8tion.jda.internal.interactions.CommandDataImpl
fun Command.toCommandData(): CommandDataImpl = CommandDataImpl(name, description).apply {
addOptions(options)
neededPermissions?.let { setDefaultPermissions(it) }
if (subcommands.isNotEmpty()) {
addSubcommands(subcommands.map { toSubcommandData() })
}
if (subcommandGroups.isNotEmpty()) {
addSubcommandGroups(
subcommandGroups.map { group ->
SubcommandGroupData(
group.name,
group.description
).addSubcommands(group.subcommands.map { toSubcommandData() })
})
}
}

View File

@@ -0,0 +1,7 @@
package fr.lucasdupont.gaytabot.command
data class SubCommandGroup(
val name: String,
val description: String,
val subCommands: List<Command>
)

View File

@@ -0,0 +1,13 @@
package fr.lucasdupont.configuration
import net.dv8tion.jda.api.OnlineStatus
import net.dv8tion.jda.api.utils.cache.CacheFlag
import org.springframework.boot.context.properties.ConfigurationProperties
@ConfigurationProperties("jda")
class JdaConfiguration {
var token: String? = null
var onlineStatus: OnlineStatus = OnlineStatus.ONLINE
var cacheFlags: Set<CacheFlag> = emptySet()
var activity: String? = null
}

View File

@@ -0,0 +1,75 @@
package fr.lucasdupont.service
import fr.lucasdupont.configuration.JdaConfiguration
import fr.lucasdupont.gaytabot.command.Command
import fr.lucasdupont.gaytabot.command.toCommandData
import net.dv8tion.jda.api.JDA
import net.dv8tion.jda.api.JDABuilder
import net.dv8tion.jda.api.entities.Activity
import net.dv8tion.jda.api.events.GenericEvent
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter
import net.dv8tion.jda.api.requests.GatewayIntent
import net.dv8tion.jda.api.utils.cache.CacheFlag
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationEventPublisher
import org.springframework.context.PayloadApplicationEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service
@Service
@EnableConfigurationProperties(JdaConfiguration::class)
class JdaService(
applicationContext: ApplicationContext,
jdaConfiguration: JdaConfiguration,
publisher: ApplicationEventPublisher
) {
private final val jda: JDA
private final val commands: Map<String, Command>
init {
val requiredIntents: Set<GatewayIntent> =
jdaConfiguration.cacheFlags
.mapNotNull(CacheFlag::getRequiredIntent)
.toSet()
val builder = JDABuilder.createDefault(jdaConfiguration.token)
.setStatus(jdaConfiguration.onlineStatus)
.enableCache(jdaConfiguration.cacheFlags)
.enableIntents(requiredIntents)
if (jdaConfiguration.activity != null) {
builder.setActivity(Activity.playing(jdaConfiguration.activity!!))
}
jda = builder
.build()
.awaitReady()
.also { jda ->
jda.addEventListener(object : ListenerAdapter() {
override fun onGenericEvent(event: GenericEvent) {
publisher.publishEvent(PayloadApplicationEvent(jda, event))
}
})
}
val contextCommands = applicationContext.getBeansOfType(Command::class.java).values
commands = contextCommands.associateBy { it.name }
val commandDataList = contextCommands.map { it.toCommandData() }
jda.updateCommands()
.addCommands(commandDataList)
.queue()
}
@EventListener(SlashCommandInteractionEvent::class)
fun onSlashCommand(event: SlashCommandInteractionEvent) {
commands[event.name]?.let { command ->
runCatching { command.execute(event) }
.onFailure { e -> error("Error while executing command '${event.name}', $e") }
}
}
}