1
0

maybe last missing step
Some checks failed
Build & Publish / build (push) Has been cancelled

This commit is contained in:
Jannik Reimers 2025-04-03 23:33:51 +02:00
parent 3ec90b83b2
commit 78572ef176
Signed by: jansel
GPG Key ID: 39C62D7D5233CFD0

View File

@ -3,9 +3,18 @@ package dev.jansel.aglaea.utils
import com.github.philippheuer.credentialmanager.domain.OAuth2Credential import com.github.philippheuer.credentialmanager.domain.OAuth2Credential
import com.github.twitch4j.TwitchClientBuilder import com.github.twitch4j.TwitchClientBuilder
import com.github.twitch4j.chat.events.channel.ChannelMessageEvent import com.github.twitch4j.chat.events.channel.ChannelMessageEvent
import dev.jansel.aglaea.botRef
import dev.jansel.aglaea.database.collections.ReplayCollection
import dev.jansel.aglaea.logger import dev.jansel.aglaea.logger
import dev.jansel.aglaea.twitchClient import dev.jansel.aglaea.twitchClient
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.channel.createMessage
import dev.kord.core.entity.channel.GuildMessageChannel
import dev.kordex.core.koin.KordExKoinComponent import dev.kordex.core.koin.KordExKoinComponent
import io.ktor.client.request.forms.*
import io.ktor.utils.io.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class Twitch : KordExKoinComponent { class Twitch : KordExKoinComponent {
suspend fun init() { suspend fun init() {
@ -23,6 +32,17 @@ class Twitch : KordExKoinComponent {
twitchClient!!.eventManager.onEvent(ChannelMessageEvent::class.java) { event -> twitchClient!!.eventManager.onEvent(ChannelMessageEvent::class.java) { event ->
if (event.customRewardId.isPresent && event.customRewardId.get() == "38157e62-de35-4a21-8200-447b55d7577e") { if (event.customRewardId.isPresent && event.customRewardId.get() == "38157e62-de35-4a21-8200-447b55d7577e") {
logger.info { "Channel points redeemed: ${event.customRewardId.get()}" } logger.info { "Channel points redeemed: ${event.customRewardId.get()}" }
runBlocking {
launch {
// Send a message to the channel
val channel = botRef!!.kordRef.getChannelOf<GuildMessageChannel>(Snowflake(1130954956892029060))
val replay = ReplayCollection().get(event.message)
channel!!.createMessage {
content = "Channel points redeemed: ${event.customRewardId.get()}"
this.addFile("replay.osr", ChannelProvider(null) { ByteReadChannel(replay!!.replayFile) })
}
}
}
} }
} }
} }