diff --git a/src/main/kotlin/dev/jansel/aglaea/utils/Twitch.kt b/src/main/kotlin/dev/jansel/aglaea/utils/Twitch.kt index 021cd91..7bb6851 100644 --- a/src/main/kotlin/dev/jansel/aglaea/utils/Twitch.kt +++ b/src/main/kotlin/dev/jansel/aglaea/utils/Twitch.kt @@ -3,9 +3,18 @@ package dev.jansel.aglaea.utils import com.github.philippheuer.credentialmanager.domain.OAuth2Credential import com.github.twitch4j.TwitchClientBuilder 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.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 io.ktor.client.request.forms.* +import io.ktor.utils.io.* +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking class Twitch : KordExKoinComponent { suspend fun init() { @@ -23,6 +32,17 @@ class Twitch : KordExKoinComponent { twitchClient!!.eventManager.onEvent(ChannelMessageEvent::class.java) { event -> if (event.customRewardId.isPresent && event.customRewardId.get() == "38157e62-de35-4a21-8200-447b55d7577e") { logger.info { "Channel points redeemed: ${event.customRewardId.get()}" } + runBlocking { + launch { + // Send a message to the channel + val channel = botRef!!.kordRef.getChannelOf(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) }) + } + } + } } } }