From be28f7ae7eb1037ecb6ff8e44a5ab12b00df9ae8 Mon Sep 17 00:00:00 2001 From: Jannik Reimers Date: Thu, 21 Nov 2024 08:58:36 +0100 Subject: [PATCH 1/4] try a different approach on loading stuff --- .idea/compiler.xml | 2 +- .idea/misc.xml | 2 +- src/main/kotlin/dev/jansel/feixiao/App.kt | 27 ++----------- .../kotlin/dev/jansel/feixiao/utils/Twitch.kt | 40 +++++++++++++++++++ .../kotlin/dev/jansel/feixiao/utils/_Utils.kt | 20 ++++++++++ 5 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt diff --git a/.idea/compiler.xml b/.idea/compiler.xml index ed2ab47..f4f3637 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,7 +1,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index c6d38c5..a4abeb1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/src/main/kotlin/dev/jansel/feixiao/App.kt b/src/main/kotlin/dev/jansel/feixiao/App.kt index f97e1dd..a2495b1 100644 --- a/src/main/kotlin/dev/jansel/feixiao/App.kt +++ b/src/main/kotlin/dev/jansel/feixiao/App.kt @@ -19,39 +19,20 @@ import kotlinx.coroutines.runBlocking var twitchClient: TwitchClient? = null val logger = KotlinLogging.logger { } +var botRef : ExtensibleBot? = null suspend fun main() { - val bot = ExtensibleBot(token) { + botRef = ExtensibleBot(token) { database(true) + twitch(true) dataCollectionMode = DataCollection.None extensions { add(::EventHooks) add(::StreamerCommand) } } - twitchClient = TwitchClientBuilder.builder() - .withEnableHelix(true) - .withClientId(twitchcid) - .withClientSecret(twitchcs) - .build() - twitchClient!!.eventManager.onEvent(ChannelGoLiveEvent::class.java) { - logger.info { "${it.channel.name} went live!" } - runBlocking { - launch { - val streamer = StreamerCollection().getData(it.channel.name) - val channel = bot.kordRef.getChannelOf(streamer!!.servers.first().channelId) - val role = streamer.servers.first().roleId - if (role != null) { - channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") - } else { - channel?.createMessage("${it.channel.name} went live: ${it.stream.title}") - } - } - } - } - - bot.start() + botRef!!.start() } diff --git a/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt b/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt new file mode 100644 index 0000000..6327551 --- /dev/null +++ b/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt @@ -0,0 +1,40 @@ +package dev.jansel.feixiao.utils + +import com.github.twitch4j.TwitchClientBuilder +import com.github.twitch4j.events.ChannelGoLiveEvent +import dev.jansel.feixiao.botRef +import dev.jansel.feixiao.database.collections.StreamerCollection +import dev.jansel.feixiao.twitchClient +import dev.kord.core.entity.channel.GuildMessageChannel +import dev.kordex.core.koin.KordExKoinComponent +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +class Twitch : KordExKoinComponent { + suspend fun init() { + twitchClient = TwitchClientBuilder.builder() + .withEnableHelix(true) + .withClientId(twitchcid) + .withClientSecret(twitchcs) + .build() + + twitchClient!!.eventManager.onEvent(ChannelGoLiveEvent::class.java) { + dev.jansel.feixiao.logger.info { "${it.channel.name} went live!" } + runBlocking { + launch { + val streamer = StreamerCollection().getData(it.channel.name) + val channel = botRef!!.kordRef.getChannelOf(streamer!!.servers.first().channelId) + val role = streamer.servers.first().roleId + if (role != null) { + channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") + } else { + channel?.createMessage("${it.channel.name} went live: ${it.stream.title}") + } + } + } + } + } + + + +} diff --git a/src/main/kotlin/dev/jansel/feixiao/utils/_Utils.kt b/src/main/kotlin/dev/jansel/feixiao/utils/_Utils.kt index ca0dc30..a7c9ec5 100644 --- a/src/main/kotlin/dev/jansel/feixiao/utils/_Utils.kt +++ b/src/main/kotlin/dev/jansel/feixiao/utils/_Utils.kt @@ -1,12 +1,17 @@ package dev.jansel.feixiao.utils +import com.github.twitch4j.TwitchClientBuilder +import com.github.twitch4j.events.ChannelGoLiveEvent import dev.jansel.feixiao.database.Database import dev.jansel.feixiao.database.collections.MetaCollection import dev.jansel.feixiao.database.collections.StreamerCollection +import dev.jansel.feixiao.twitchClient import dev.kord.common.entity.Snowflake +import dev.kord.core.entity.channel.GuildMessageChannel import dev.kordex.core.builders.ExtensibleBotBuilder import dev.kordex.core.utils.env import dev.kordex.core.utils.loadModule +import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.koin.dsl.bind @@ -37,3 +42,18 @@ suspend inline fun ExtensibleBotBuilder.database(migrate: Boolean) { } } } + +suspend inline fun ExtensibleBotBuilder.twitch(active: Boolean) { + hooks { + beforeKoinSetup { + loadModule { + single { Twitch() } bind Twitch::class + } + + if (active) { + Twitch().init() + } + } + } + +} From accd4d19758ef0b5b62db32f3d05b4b2a88c333f Mon Sep 17 00:00:00 2001 From: Jannik Reimers Date: Thu, 28 Nov 2024 09:01:24 +0100 Subject: [PATCH 2/4] better loading system should work, will see it later during prod --- src/main/kotlin/dev/jansel/feixiao/App.kt | 10 +--------- src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt | 2 ++ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/dev/jansel/feixiao/App.kt b/src/main/kotlin/dev/jansel/feixiao/App.kt index 16167c9..afdfc21 100644 --- a/src/main/kotlin/dev/jansel/feixiao/App.kt +++ b/src/main/kotlin/dev/jansel/feixiao/App.kt @@ -3,23 +3,15 @@ */ package dev.jansel.feixiao -import com.github.philippheuer.events4j.reactor.ReactorEventHandler import com.github.twitch4j.TwitchClient -import com.github.twitch4j.TwitchClientBuilder -import com.github.twitch4j.events.ChannelGoLiveEvent -import dev.jansel.feixiao.database.collections.StreamerCollection import dev.jansel.feixiao.extensions.EventHooks import dev.jansel.feixiao.extensions.StreamerCommand import dev.jansel.feixiao.utils.database import dev.jansel.feixiao.utils.token -import dev.jansel.feixiao.utils.twitchcid -import dev.jansel.feixiao.utils.twitchcs -import dev.kord.core.entity.channel.GuildMessageChannel import dev.kordex.core.ExtensibleBot import dev.kordex.core.i18n.SupportedLocales import io.github.oshai.kotlinlogging.KotlinLogging -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking +import dev.jansel.feixiao.utils.twitch var twitchClient: TwitchClient? = null val logger = KotlinLogging.logger { } diff --git a/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt b/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt index 6327551..07b3d2e 100644 --- a/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt +++ b/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt @@ -1,5 +1,6 @@ package dev.jansel.feixiao.utils +import com.github.philippheuer.events4j.reactor.ReactorEventHandler import com.github.twitch4j.TwitchClientBuilder import com.github.twitch4j.events.ChannelGoLiveEvent import dev.jansel.feixiao.botRef @@ -14,6 +15,7 @@ class Twitch : KordExKoinComponent { suspend fun init() { twitchClient = TwitchClientBuilder.builder() .withEnableHelix(true) + .withDefaultEventHandler(ReactorEventHandler::class.java) .withClientId(twitchcid) .withClientSecret(twitchcs) .build() From 45da7ed2daf50bfe1aa8d1c038b650cff6deb8e0 Mon Sep 17 00:00:00 2001 From: Jannik Reimers Date: Thu, 28 Nov 2024 09:06:11 +0100 Subject: [PATCH 3/4] MAYBE ALSO IMPLEMENT CHANGES THAT WERE MADE SINCE THIS BRANCH WAS MADE --- .../kotlin/dev/jansel/feixiao/utils/Twitch.kt | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt b/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt index 07b3d2e..1f45103 100644 --- a/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt +++ b/src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt @@ -25,12 +25,37 @@ class Twitch : KordExKoinComponent { runBlocking { launch { val streamer = StreamerCollection().getData(it.channel.name) - val channel = botRef!!.kordRef.getChannelOf(streamer!!.servers.first().channelId) - val role = streamer.servers.first().roleId - if (role != null) { - channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") - } else { - channel?.createMessage("${it.channel.name} went live: ${it.stream.title}") + for (server in streamer!!.servers) { + val channel = botRef!!.kordRef.getChannelOf(server.channelId) + val role = server.roleId + val livemessage = server.liveMessage + + if (role != null) { + if (livemessage != null) { + channel?.createMessage( + livemessage + .replace("{name}", it.channel.name) + .replace("{category}", it.stream.gameName) + .replace("{title}", it.stream.title) + .replace("{url}", "https://twitch.tv/${it.channel.name}") + .replace("{role}", "<@&$role>") + ) + } else { + channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") + } + } else { + if (livemessage != null) { + channel?.createMessage( + livemessage + .replace("{name}", it.channel.name) + .replace("{category}", it.stream.gameName) + .replace("{title}", it.stream.title) + .replace("{url}", "https://twitch.tv/${it.channel.name}") + ) + } else { + channel?.createMessage("https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") + } + } } } } From 5a2b1ec4387338f40c1084f9b1d9fcd3577baaea Mon Sep 17 00:00:00 2001 From: Jannik Reimers Date: Thu, 28 Nov 2024 09:45:03 +0100 Subject: [PATCH 4/4] finally i'm able to update gradle to 8.11.1 --- build.gradle.kts | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e53343b..802ad4c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -89,6 +89,6 @@ docker { } tasks.wrapper { - gradleVersion = "8.10.2" + gradleVersion = "8.11.1" distributionType = Wrapper.DistributionType.BIN } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index df97d72..e2847c8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle.kts b/settings.gradle.kts index fc0b921..84e3ff8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,8 +6,8 @@ pluginManagement { id("com.github.johnrengelman.shadow") version "8.1.1" - id("dev.kordex.gradle.docker") version "1.5.8" - id("dev.kordex.gradle.kordex") version "1.5.8" + id("dev.kordex.gradle.docker") version "1.6.0" + id("dev.kordex.gradle.kordex") version "1.6.0" } repositories { gradlePluginPortal()