diff --git a/src/main/kotlin/dev/jansel/feixiao/App.kt b/src/main/kotlin/dev/jansel/feixiao/App.kt index f1ddbde..e6fb71c 100644 --- a/src/main/kotlin/dev/jansel/feixiao/App.kt +++ b/src/main/kotlin/dev/jansel/feixiao/App.kt @@ -12,7 +12,6 @@ import dev.jansel.feixiao.extensions.StreamerCommand import dev.jansel.feixiao.utils.* import dev.kord.core.entity.channel.GuildMessageChannel import dev.kordex.core.ExtensibleBot -import dev.kordex.data.api.DataCollection import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -39,12 +38,33 @@ suspend fun main() { runBlocking { launch { val streamer = StreamerCollection().getData(it.channel.name) - val channel = bot.kordRef.getChannelOf(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("https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") + for (server in streamer!!.servers) { + val channel = bot.kordRef.getChannelOf(server.channelId) + val role = server.roleId + val livemessage = server.liveMessage + + if (role != null) { + if (livemessage != null) { + channel?.createMessage(livemessage + .replace("{name}", it.channel.name) + .replace("{category}", it.stream.gameName) + .replace("{title}", it.stream.title) + .replace("{url}", "https://twitch.tv/${it.channel.name}") + .replace("{role}", "<@&$role>")) + } else { + channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") + } + } else { + if (livemessage != null) { + channel?.createMessage(livemessage + .replace("{name}", it.channel.name) + .replace("{category}", it.stream.gameName) + .replace("{title}", it.stream.title) + .replace("{url}", "https://twitch.tv/${it.channel.name}")) + } else { + channel?.createMessage("https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") + } + } } } } diff --git a/src/main/kotlin/dev/jansel/feixiao/extensions/StreamerCommand.kt b/src/main/kotlin/dev/jansel/feixiao/extensions/StreamerCommand.kt index a2522a4..048c96c 100644 --- a/src/main/kotlin/dev/jansel/feixiao/extensions/StreamerCommand.kt +++ b/src/main/kotlin/dev/jansel/feixiao/extensions/StreamerCommand.kt @@ -29,7 +29,7 @@ class StreamerCommand : Extension() { } action { val streamer = arguments.streamer - StreamerCollection().updateData(guild!!.id, arguments.channel.id, streamer, arguments.role?.id) + StreamerCollection().updateData(guild!!.id, arguments.channel.id, streamer, arguments.role?.id, arguments.message) twitchClient!!.clientHelper.enableStreamEventListener(streamer) respond { content = "Added streamer $streamer" @@ -46,7 +46,7 @@ class StreamerCommand : Extension() { } action { val streamer = arguments.streamer - StreamerCollection().removeData(guild!!.id, channel.id, streamer, null) + StreamerCollection().removeData(guild!!.id, channel.id, streamer, null, null) respond { content = "Removed streamer $streamer" } @@ -70,6 +70,10 @@ class StreamerCommand : Extension() { name = "role" description = "Role to ping when the streamer goes live" } + val message by string { + name = "message" + description = "Message to send when the streamer goes live. Possible placeholders: {url}, {name}, {title}, {category}, {role} (if set)" + } } inner class RemoveStreamerArgs : Arguments() {