Skip to content

Commit

Permalink
fix: not loading aluna properties during scope creation
Browse files Browse the repository at this point in the history
chore: 0.0.12_5.0.0-alpha.9
  • Loading branch information
itsmefox committed Apr 14, 2022
1 parent 39d205a commit 5197e39
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group "io.viascom.discord.bot"
version "0.0.11_5.0.0-alpha.9"
version "0.0.12_5.0.0-alpha.9"

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.aventrix.jnanoid.jnanoid.NanoIdUtils
import io.viascom.discord.bot.starter.bot.DiscordBot
import io.viascom.discord.bot.starter.bot.handler.CommandScopedObject
import io.viascom.discord.bot.starter.bot.listener.EventWaiter
import io.viascom.discord.bot.starter.property.AlunaProperties
import io.viascom.discord.bot.starter.util.AlunaThreadPool
import net.dv8tion.jda.internal.interactions.CommandDataImpl
import org.slf4j.Logger
Expand All @@ -16,17 +15,23 @@ import org.springframework.core.NamedInheritableThreadLocal
import java.time.LocalDateTime
import java.util.*
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.ScheduledThreadPoolExecutor
import java.util.concurrent.TimeUnit

class CommandScope(private val context: ConfigurableApplicationContext, private val alunaProperties: AlunaProperties) : Scope {
class CommandScope(private val context: ConfigurableApplicationContext) : Scope {

val logger: Logger = LoggerFactory.getLogger(javaClass)

private val scopedObjects = Collections.synchronizedMap(HashMap<BeanName, HashMap<DiscordStateId, HashMap<UniqueId, ScopedObjectData>>>())
private val scopedObjectsTimeoutScheduler =
AlunaThreadPool.getScheduledThreadPool(alunaProperties.thread.scopedObjectsTimeoutScheduler, "Aluna-Scoped-Objects-Timeout-Pool-%d", true)
private var scopedObjectsTimeoutScheduler: ScheduledThreadPoolExecutor

private val scopedObjectsTimeoutScheduledTask = Collections.synchronizedMap(HashMap<UniqueId, ScheduledFuture<*>>())

init {
val scopedObjectsTimeoutScheduler = context.environment.getProperty("aluna.thread.scoped-objects-timeout-scheduler", Int::class.java, 2)
this.scopedObjectsTimeoutScheduler = AlunaThreadPool.getScheduledThreadPool(scopedObjectsTimeoutScheduler, "Aluna-Scoped-Objects-Timeout-Pool-%d", true)
}

override fun get(name: String, objectFactory: ObjectFactory<*>): Any {
//If state id is not set, a new instance is returned
if (DiscordContext.discordState?.id == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package io.viascom.discord.bot.starter.configuration.scope

import io.viascom.discord.bot.starter.property.AlunaProperties
import org.springframework.beans.factory.config.BeanFactoryPostProcessor
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory
import org.springframework.context.ConfigurableApplicationContext

open class ScopeBeanFactoryPostProcessor(
private val context: ConfigurableApplicationContext,
private val alunaProperties: AlunaProperties
private val context: ConfigurableApplicationContext
) : BeanFactoryPostProcessor {

override fun postProcessBeanFactory(factory: ConfigurableListableBeanFactory) {
factory.registerScope("command", CommandScope(context, alunaProperties))
factory.registerScope("command", CommandScope(context))
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.viascom.discord.bot.starter.configuration.scope

import io.viascom.discord.bot.starter.property.AlunaProperties
import org.springframework.beans.factory.config.BeanFactoryPostProcessor
import org.springframework.context.ConfigurableApplicationContext
import org.springframework.context.annotation.Bean
Expand All @@ -10,8 +9,8 @@ import org.springframework.context.annotation.Configuration
open class ScopeConfig {

@Bean
open fun beanFactoryPostProcessor(context: ConfigurableApplicationContext, alunaProperties: AlunaProperties): BeanFactoryPostProcessor {
return ScopeBeanFactoryPostProcessor(context, alunaProperties)
open fun beanFactoryPostProcessor(context: ConfigurableApplicationContext): BeanFactoryPostProcessor {
return ScopeBeanFactoryPostProcessor(context)
}

}

0 comments on commit 5197e39

Please sign in to comment.