Skip to content

Commit

Permalink
feat: add FastMutualGuildsCache
Browse files Browse the repository at this point in the history
feat: add InteractionDetailsProvider for /system-command
chore: update readme
chore: add .editorconfig
chore: update copyright date
  • Loading branch information
itsmefox committed Feb 22, 2025
1 parent 93dd799 commit fd7830b
Show file tree
Hide file tree
Showing 216 changed files with 3,249 additions and 298 deletions.
1,832 changes: 1,832 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<p align="center">
<a href="/~https://github.com/viascom/aluna-spring-boot-starter/releases"><img src="https://img.shields.io/maven-metadata/v.svg?label=maven-central&metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fviascom%2Fdiscord%2Fbot%2Faluna-spring-boot-starter%2Fmaven-metadata.xml"
alt="Maven central"></a>
<a href=""><img src="https://img.shields.io/badge/JDA--Version-5.1.2-blue.svg"
<a href=""><img src="https://img.shields.io/badge/JDA--Version-5.3.0-blue.svg"
alt="JDA-Version "></a>
<img src="https://img.shields.io/badge/Kotlin-2.0.20-%238052ff?logo=kotlin"
<img src="https://img.shields.io/badge/Kotlin-2.1.10-%238052ff?logo=kotlin"
alt="Kotlin Version">
<a href="http://www.apache.org/licenses/"><img src="https://img.shields.io/badge/license-Apache_2.0-blue.svg"
alt="license Apache 2.0"></a>
Expand All @@ -23,6 +23,7 @@

| aluna-spring-boot-starter | JDA | Spring Boot | Kotlin | Emoji Library | nanoid-kotlin |
|:--------------------------|:--------------------------------------------------------------------------:|:--------------------------------------------------------------------------:|:----------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------:|
| `1.3.0` | <img src="https://img.shields.io/badge/5.3.0-brightgreen.svg" alt="5.3.0"> | <img src="https://img.shields.io/badge/3.4.3-brightgreen.svg" alt="3.4.3"> | <img src="https://img.shields.io/badge/2.1.10-brightgreen.svg" alt="2.1.10"> | <img src="https://img.shields.io/badge/JEmoji-1.6.0-brightgreen.svg" alt="JEmoji 1.6.0"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
| `1.1.10` | <img src="https://img.shields.io/badge/5.1.2-brightgreen.svg" alt="5.1.2"> | <img src="https://img.shields.io/badge/3.3.4-brightgreen.svg" alt="3.3.4"> | <img src="https://img.shields.io/badge/2.0.20-brightgreen.svg" alt="2.0.20"> | <img src="https://img.shields.io/badge/JEmoji-1.5.1-brightgreen.svg" alt="JEmoji 1.5.1"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
| `1.1.9` | <img src="https://img.shields.io/badge/5.1.0-brightgreen.svg" alt="5.1.0"> | <img src="https://img.shields.io/badge/3.3.2-brightgreen.svg" alt="3.3.2"> | <img src="https://img.shields.io/badge/2.0.10-brightgreen.svg" alt="2.0.10"> | <img src="https://img.shields.io/badge/JEmoji-1.5.1-brightgreen.svg" alt="JEmoji 1.5.1"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
| `1.1.8` | <img src="https://img.shields.io/badge/5.0.2-brightgreen.svg" alt="5.0.2"> | <img src="https://img.shields.io/badge/3.3.2-brightgreen.svg" alt="3.3.2"> | <img src="https://img.shields.io/badge/2.0.10-brightgreen.svg" alt="2.0.10"> | <img src="https://img.shields.io/badge/JEmoji-1.4.1-brightgreen.svg" alt="JEmoji 1.4.1"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
Expand All @@ -36,7 +37,7 @@ Gradle:

```gradle
dependencies {
implementation 'io.viascom.discord.bot:aluna-spring-boot-starter:1.1.10'
implementation 'io.viascom.discord.bot:aluna-spring-boot-starter:1.3.0'
}
```

Expand All @@ -46,7 +47,7 @@ Maven:
<dependency>
<groupId>io.viascom.discord.bot</groupId>
<artifactId>aluna-spring-boot-starter</artifactId>
<version>1.1.10</version>
<version>1.3.0</version>
</dependency>
```

Expand Down
1 change: 1 addition & 0 deletions VERSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| aluna-spring-boot-starter | JDA | Spring Boot | Kotlin | Emoji Library | nanoid-kotlin |
|:--------------------------|:-------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------:|:----------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------:|
| `1.3.0` | <img src="https://img.shields.io/badge/5.3.0-brightgreen.svg" alt="5.3.0"> | <img src="https://img.shields.io/badge/3.4.3-brightgreen.svg" alt="3.4.3"> | <img src="https://img.shields.io/badge/2.1.10-brightgreen.svg" alt="2.1.10"> | <img src="https://img.shields.io/badge/JEmoji-1.6.0-brightgreen.svg" alt="JEmoji 1.6.0"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
| `1.1.10` | <img src="https://img.shields.io/badge/5.1.2-brightgreen.svg" alt="5.1.2"> | <img src="https://img.shields.io/badge/3.3.4-brightgreen.svg" alt="3.3.4"> | <img src="https://img.shields.io/badge/2.0.20-brightgreen.svg" alt="2.0.20"> | <img src="https://img.shields.io/badge/JEmoji-1.5.2-brightgreen.svg" alt="JEmoji 1.5.2"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
| `1.1.9` | <img src="https://img.shields.io/badge/5.1.0-brightgreen.svg" alt="5.1.0"> | <img src="https://img.shields.io/badge/3.3.2-brightgreen.svg" alt="3.3.2"> | <img src="https://img.shields.io/badge/2.0.10-brightgreen.svg" alt="2.0.10"> | <img src="https://img.shields.io/badge/JEmoji-1.5.1-brightgreen.svg" alt="JEmoji 1.5.1"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
| `1.1.8` | <img src="https://img.shields.io/badge/5.0.2-brightgreen.svg" alt="5.0.2"> | <img src="https://img.shields.io/badge/3.3.2-brightgreen.svg" alt="3.3.2"> | <img src="https://img.shields.io/badge/2.0.10-brightgreen.svg" alt="2.0.10"> | <img src="https://img.shields.io/badge/JEmoji-1.4.1-brightgreen.svg" alt="JEmoji 1.4.1"> | <img src="https://img.shields.io/badge/1.0.1-brightgreen.svg" alt="1.0.1"> |
Expand Down
27 changes: 16 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand All @@ -6,7 +7,7 @@ plugins {
id "java-library"
id "maven-publish"
id "signing"
id "org.jetbrains.kotlin.jvm" version "2.1.0"
id "org.jetbrains.kotlin.jvm" version "2.1.10"
id "org.jetbrains.kotlin.kapt" version "2.1.10"
id "org.springframework.boot" version "3.4.3"
id "io.spring.dependency-management" version "1.1.7"
Expand All @@ -16,8 +17,8 @@ plugins {

ext {
major = 1
minor = 1
patch = 10
minor = 3
patch = 0

isCiServer = System.getenv("GITHUB_ACTIONS") != null || System.getProperty("GITHUB_ACTIONS") != null

Expand Down Expand Up @@ -93,6 +94,9 @@ dependencies {
//====== Gson ======
compileOnly "com.google.code.gson:gson:$gsonVersion"

//====== Caching ======
implementation "com.github.ben-manes.caffeine:caffeine:3.1.8"

//====== Emoji Helper ======
api "net.fellbaum:jemoji:$jemojiVersion"

Expand Down Expand Up @@ -227,26 +231,27 @@ tasks.withType(Sign).configureEach {
onlyIf { isCiServer }
}

tasks.withType(DokkaTask.class).configureEach {
tasks.withType(DokkaTask).configureEach {
dokkaSourceSets.configureEach {
moduleName.set(project.name)
moduleVersion.set(project.version.toString())
includes.from("README.md")
jdkVersion.set(17)

sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(URL("/~https://github.com/viascom/aluna-spring-boot-starter/tree/master/src/main/kotlin"))
remoteUrl.set(new URI("/~https://github.com/viascom/aluna-spring-boot-starter/tree/master/src/main/kotlin").toURL())
remoteLineSuffix.set("#L")
}

perPackageOption {
documentedVisibilities.set([Visibility.PUBLIC])
}

externalDocumentationLink {
url.set(new URI("ttps://ci.dv8tion.net/job/JDA5/javadoc/").toURL())
url.set(new URI("https://ci.dv8tion.net/job/JDA5/javadoc/").toURL())
}

perPackageOption {
matchingRegex.set(".*")
suppress.set(false)
documentedVisibilities.set([DokkaConfiguration.Visibility.PUBLIC]) // Only public elements
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -28,12 +28,10 @@ import io.viascom.discord.bot.aluna.bot.command.systemcommand.SystemCommandEmoji
import io.viascom.discord.bot.aluna.bot.handler.*
import io.viascom.discord.bot.aluna.bot.listener.*
import io.viascom.discord.bot.aluna.bot.shardmanager.*
import io.viascom.discord.bot.aluna.configuration.condition.ConditionalOnAlunaShutdownHook
import io.viascom.discord.bot.aluna.configuration.condition.ConditionalOnJdaEnabled
import io.viascom.discord.bot.aluna.configuration.condition.ConditionalOnSystemCommandEnabled
import io.viascom.discord.bot.aluna.configuration.condition.ConditionalOnTranslationEnabled
import io.viascom.discord.bot.aluna.configuration.condition.*
import io.viascom.discord.bot.aluna.event.EventPublisher
import io.viascom.discord.bot.aluna.property.*
import kotlinx.coroutines.launch
import net.dv8tion.jda.api.sharding.ShardManager
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -116,7 +114,9 @@ open class AlunaAutoConfiguration {
discordBot.latchCount = shardManagerBuilder.getLatchCount()

if (alunaProperties.discord.autoLoginOnStartup) {
discordBot.login()
AlunaDispatchers.InternalScope.launch {
discordBot.login()
}
} else {
logger.debug("AutoLoginOnStartup is disabled. Not awaiting for shards to connect.")
}
Expand All @@ -141,7 +141,9 @@ open class AlunaAutoConfiguration {
discordBot.latchCount = shardManagerBuilder.getLatchCount()

if (alunaProperties.discord.autoLoginOnStartup) {
discordBot.login()
AlunaDispatchers.InternalScope.launch {
discordBot.login()
}
} else {
logger.debug("AutoLoginOnStartup is disabled. Not awaiting for shards to connect.")
}
Expand Down Expand Up @@ -281,7 +283,22 @@ open class AlunaAutoConfiguration {
@ConditionalOnJdaEnabled
@ConditionalOnMissingBean
open fun defaultInteractionInitializerCondition(): InteractionInitializerCondition {
logger.debug("Enable DefaultInteractionInitializerCondition")
return DefaultInteractionInitializerCondition()
}

/**
* Returns the default implementation of the FastMutualGuildsCache interface.
*
* @return the created instance of DefaultFastMutualGuildsCache
*/
@Bean
@ConditionalOnJdaEnabled
@ConditionalOnFastMutualGuildCacheEnabled
@ConditionalOnMissingBean(FastMutualGuildsCache::class)
open fun defaultFastMutualGuildsCache(shardManager: ShardManager, alunaProperties: AlunaProperties): FastMutualGuildsCache {
logger.debug("Enable DefaultFastMutualGuildsCache")
return DefaultFastMutualGuildsCache(shardManager, alunaProperties)
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
19 changes: 11 additions & 8 deletions src/main/kotlin/io/viascom/discord/bot/aluna/bot/DiscordBot.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -125,7 +125,6 @@ open class DiscordBot(
internal val commandHistory = MutableSharedFlow<CommandUsage>(replay = 15, extraBufferCapacity = 15, BufferOverflow.DROP_OLDEST)
val commandHistoryFlow = commandHistory.asSharedFlow()


fun login() {
if (isLoggedIn) {
logger.warn("ShardManager already logged in. Skipping login.")
Expand Down Expand Up @@ -773,12 +772,6 @@ open class DiscordBot(

}

internal typealias InteractionId = String
internal typealias OptionName = String
internal typealias CooldownKey = String
internal typealias MessageId = String
internal typealias LastUsage = LocalDateTime

/**
* Queue an interaction and register listeners for it.
*
Expand Down Expand Up @@ -907,3 +900,13 @@ val JDA.scope: CoroutineScope get() = (eventManager as? CoroutineEventManager) ?
* If this instance does not use the coroutine event manager, this returns the default scope from [getDefaultJDAScope].
*/
val ShardManager.scope: CoroutineScope get() = (shardCache.firstOrNull()?.eventManager as? CoroutineEventManager) ?: AlunaDispatchers.InternalScope

internal typealias InteractionId = String
internal typealias OptionName = String
internal typealias CooldownKey = String
internal typealias LastUsage = LocalDateTime

typealias UserId = Long
typealias GuildId = Long
typealias ChannelId = Long
typealias MessageId = String
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -43,6 +43,11 @@ class DefaultHelpCommand : CoroutineDiscordCommand("help", "Shows information ab
this.beanCallOnDestroy = false
}

override fun initCommandOptions() {
setContexts(alunaProperties.command.helpCommand.contexts)
setIntegrationTypes(alunaProperties.command.helpCommand.integrationTypes)
}

override suspend fun execute(event: SlashCommandInteractionEvent) {
val embed = EmbedBuilder()
.setAuthor(alunaProperties.command.helpCommand.title, null, event.jda.selfUser.effectiveAvatarUrl)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -64,6 +64,8 @@ class SystemCommand(
override fun initCommandOptions() {
@OptIn(Experimental::class)
specificServers = alunaProperties.command.systemCommand.servers
setContexts(alunaProperties.command.systemCommand.contexts)
setIntegrationTypes(alunaProperties.command.systemCommand.integrationTypes)
addOptions(commandOption, argsOption)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Viascom Ltd liab. Co
* Copyright 2025 Viascom Ltd liab. Co
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down
Loading

0 comments on commit fd7830b

Please sign in to comment.