try a different approach on loading stuff
This commit is contained in:
parent
c31f2cc149
commit
be28f7ae7e
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<bytecodeTargetLevel target="13">
|
<bytecodeTargetLevel target="21">
|
||||||
<module name="ext-common" target="1.8" />
|
<module name="ext-common" target="1.8" />
|
||||||
<module name="ext-common.main" target="1.8" />
|
<module name="ext-common.main" target="1.8" />
|
||||||
<module name="ext-common.test" target="1.8" />
|
<module name="ext-common.test" target="1.8" />
|
||||||
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -5,7 +5,7 @@
|
|||||||
<file type="web" url="file://$PROJECT_DIR$/../ext-common" />
|
<file type="web" url="file://$PROJECT_DIR$/../ext-common" />
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="azul-21" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="azul-21" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -19,39 +19,20 @@ import kotlinx.coroutines.runBlocking
|
|||||||
|
|
||||||
var twitchClient: TwitchClient? = null
|
var twitchClient: TwitchClient? = null
|
||||||
val logger = KotlinLogging.logger { }
|
val logger = KotlinLogging.logger { }
|
||||||
|
var botRef : ExtensibleBot? = null
|
||||||
|
|
||||||
suspend fun main() {
|
suspend fun main() {
|
||||||
val bot = ExtensibleBot(token) {
|
botRef = ExtensibleBot(token) {
|
||||||
database(true)
|
database(true)
|
||||||
|
twitch(true)
|
||||||
dataCollectionMode = DataCollection.None
|
dataCollectionMode = DataCollection.None
|
||||||
extensions {
|
extensions {
|
||||||
add(::EventHooks)
|
add(::EventHooks)
|
||||||
add(::StreamerCommand)
|
add(::StreamerCommand)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
twitchClient = TwitchClientBuilder.builder()
|
|
||||||
.withEnableHelix(true)
|
|
||||||
.withClientId(twitchcid)
|
|
||||||
.withClientSecret(twitchcs)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
twitchClient!!.eventManager.onEvent(ChannelGoLiveEvent::class.java) {
|
botRef!!.start()
|
||||||
logger.info { "${it.channel.name} went live!" }
|
|
||||||
runBlocking {
|
|
||||||
launch {
|
|
||||||
val streamer = StreamerCollection().getData(it.channel.name)
|
|
||||||
val channel = bot.kordRef.getChannelOf<GuildMessageChannel>(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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
40
src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt
Normal file
40
src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt
Normal file
@ -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<GuildMessageChannel>(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}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,17 @@
|
|||||||
package dev.jansel.feixiao.utils
|
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.Database
|
||||||
import dev.jansel.feixiao.database.collections.MetaCollection
|
import dev.jansel.feixiao.database.collections.MetaCollection
|
||||||
import dev.jansel.feixiao.database.collections.StreamerCollection
|
import dev.jansel.feixiao.database.collections.StreamerCollection
|
||||||
|
import dev.jansel.feixiao.twitchClient
|
||||||
import dev.kord.common.entity.Snowflake
|
import dev.kord.common.entity.Snowflake
|
||||||
|
import dev.kord.core.entity.channel.GuildMessageChannel
|
||||||
import dev.kordex.core.builders.ExtensibleBotBuilder
|
import dev.kordex.core.builders.ExtensibleBotBuilder
|
||||||
import dev.kordex.core.utils.env
|
import dev.kordex.core.utils.env
|
||||||
import dev.kordex.core.utils.loadModule
|
import dev.kordex.core.utils.loadModule
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.koin.dsl.bind
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user