1
0

test twitch stuff

This commit is contained in:
Jannik Reimers 2025-04-03 19:59:31 +02:00
parent 2037ba906f
commit 0be5976be2
Signed by: jansel
GPG Key ID: 39C62D7D5233CFD0
5 changed files with 75 additions and 2 deletions

View File

@ -248,7 +248,7 @@ formatting:
active: true
autoCorrect: true
Filename:
active: true
active: false
FinalNewline:
active: true
autoCorrect: true

View File

@ -3,12 +3,19 @@
*/
package dev.jansel.aglaea
import com.github.twitch4j.TwitchClient
import dev.jansel.aglaea.extensions.TestExtension
import dev.jansel.aglaea.utils.twitch
import dev.kord.common.entity.Snowflake
import dev.kordex.core.ExtensibleBot
import dev.kordex.core.utils.env
import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.File
var twitchClient: TwitchClient? = null
val logger = KotlinLogging.logger { }
var botRef: ExtensibleBot? = null
val TEST_SERVER_ID = Snowflake(
env("TEST_SERVER").toLong() // Get the test server ID from the env vars or a .env file
)
@ -20,7 +27,7 @@ suspend fun main() {
extensions {
add(::TestExtension)
}
twitch(true)
if (devMode) {
// In development mode, load any plugins from `src/main/dist/plugin` if it exists.
plugins {

View File

@ -0,0 +1,25 @@
package dev.jansel.aglaea.extensions
import com.github.philippheuer.credentialmanager.domain.OAuth2Credential
import dev.jansel.aglaea.logger
import dev.jansel.aglaea.twitchClient
import dev.jansel.aglaea.utils.twitchcid
import dev.jansel.aglaea.utils.twitchcs
import dev.kord.core.event.gateway.ReadyEvent
import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.event
class EventHooks : Extension() {
override val name = "eventhooks"
override suspend fun setup() {
event<ReadyEvent> {
action {
// This is where you can add any code that should run when the bot is ready
// For example, you can initialize any services or start any background tasks
logger.info { "Bot is ready!" }
twitchClient!!.pubSub.listenForChannelPointsRedemptionEvents(OAuth2Credential(twitchcid, twitchcs), "120275141")
}
}
}
}

View File

@ -0,0 +1,18 @@
package dev.jansel.aglaea.utils
import com.github.philippheuer.events4j.reactor.ReactorEventHandler
import com.github.twitch4j.TwitchClientBuilder
import dev.jansel.aglaea.twitchClient
import dev.kordex.core.koin.KordExKoinComponent
class Twitch : KordExKoinComponent {
suspend fun init() {
twitchClient = TwitchClientBuilder.builder()
.withEnableHelix(true)
.withEnablePubSub(true)
.withDefaultEventHandler(ReactorEventHandler::class.java)
.withClientId(twitchcid)
.withClientSecret(twitchcs)
.build()
}
}

View File

@ -0,0 +1,23 @@
package dev.jansel.aglaea.utils
import dev.kordex.core.builders.ExtensibleBotBuilder
import dev.kordex.core.utils.env
import dev.kordex.core.utils.loadModule
import org.koin.dsl.bind
val twitchcid = env("TWITCH_CLIENT_ID")
val twitchcs = env("TWITCH_CLIENT_SECRET")
suspend inline fun ExtensibleBotBuilder.twitch(active: Boolean) {
hooks {
beforeKoinSetup {
loadModule {
single { Twitch() } bind Twitch::class
}
if (active) {
Twitch().init()
}
}
}
}