hopefully running

This commit is contained in:
Jannik Reimers 2024-10-28 15:20:23 +01:00
parent 629a5cc746
commit b62c04f77b
Signed by: jansel
GPG key ID: 39C62D7D5233CFD0
9 changed files with 73 additions and 82 deletions

View file

@ -3,23 +3,17 @@
*/
package dev.jansel.feixiao
import dev.kord.common.entity.Snowflake
import dev.kordex.core.ExtensibleBot
import dev.kordex.core.utils.env
import dev.jansel.feixiao.extensions.EventHooks
import dev.jansel.feixiao.extensions.MessageEvents
val TEST_SERVER_ID = Snowflake(
env("TEST_SERVER").toLong() // Get the test server ID from the env vars or a .env file
)
private val TOKEN = env("TOKEN") // Get the bot' token from the env vars or a .env file
import dev.jansel.feixiao.utils.*
import dev.kordex.core.ExtensibleBot
suspend fun main() {
val bot = ExtensibleBot(TOKEN) {
val bot = ExtensibleBot(token) {
extensions {
add(::MessageEvents)
add(::EventHooks)
}
}
bot.start()
}

View file

@ -0,0 +1,44 @@
package dev.jansel.feixiao.extensions
import com.github.twitch4j.TwitchClientBuilder
import com.github.twitch4j.events.ChannelGoLiveEvent
import dev.jansel.feixiao.utils.tchannelid
import dev.jansel.feixiao.utils.tserverid
import dev.jansel.feixiao.utils.twitchcid
import dev.jansel.feixiao.utils.twitchcs
import dev.kord.core.behavior.getChannelOf
import dev.kord.core.entity.channel.GuildMessageChannel
import dev.kord.core.event.gateway.ReadyEvent
import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.event
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class EventHooks : Extension() {
override val name = "eventhooks"
override suspend fun setup() {
event<ReadyEvent> {
action {
println("Bot is ready!")
val twitchClient = TwitchClientBuilder.builder()
.withEnableHelix(true)
.withClientId(twitchcid)
.withClientSecret(twitchcs)
.build()
twitchClient.clientHelper.enableStreamEventListener("janselosu")
// Register a listener for when the channel goes live
twitchClient.eventManager.onEvent(ChannelGoLiveEvent::class.java) {
runBlocking {
launch {
val onlineLog =
kord.getGuildOrNull(tserverid)?.getChannelOf<GuildMessageChannel>(tchannelid)
onlineLog?.createMessage("${it.channel} is now live at https://twitch.tv/${it.channel}")
}
}
}
}
}
}
}

View file

@ -0,0 +1,10 @@
package dev.jansel.feixiao.utils
import dev.kord.common.entity.Snowflake
import dev.kordex.core.utils.env
val twitchcid = env("TWITCH_CLIENT_ID")
val twitchcs = env("TWITCH_CLIENT_SECRET")
val token = env("TOKEN")
val tserverid = Snowflake(env("TEST_SERVER").toLong())
val tchannelid = Snowflake(env("TEST_CHANNEL").toLong())

View file

@ -1,5 +1,4 @@
import ch.qos.logback.core.joran.spi.ConsoleTarget
import ch.qos.logback.core.ConsoleAppender
def environment = System.getenv("ENVIRONMENT") ?: "production"