filwiesner / TmiK

Twitch messaging in Kotlin - Simple DSL for interacting with Twitch chat
MIT License
8 stars 1 forks source link
kotlin kotlin-dsl kotlin-js kotlin-jvm multiplatform twitch twitch-irc

TmiK

Download Download Codacy Badge GitHub
Twitch messaging in Kotlin
Simple DSL for interacting with Twitch chat

See the Documentation for more information

State

Only JVM and JS are targeted but I hope I will be able to add Native in the future.

Example

Example of simple bot

tmi(token) {
    + Reconnect(5) // Tries to reconnect for five times if network fails (and re-joins all channels)

    channel("MyChannel") {

        // Convenient way of listening to commands
        commands('!') {
            moderators { 
                "uptime" receive { // on "!uptime" command from moderator
                    sendMessage("Stream has been running for ${getUptime()} minutes")
                }
            }

            "|h,help|" {
                onReceive { // on "!h" or "!help" 
                    // Whisper back to user who sent the command using context 
                    whisper("Psst, ask me about shedule using \"!schedule {day}\"")
                }
                "schedule {day}" receive { paramaters -> // e.g. "!h schedule monday
                    val day = paramaters["day"]
                    sendMessage("Stream starts in ${getShedule(day)} on $day")
                }
            }
        }

        // Or use just plain old listeners

        onMessage {
            println("Message from channel $channel received: $text")
        }

        subscribers {
            onSubGift {
                sendMessage("Awwww, subs giving subs <3")
            }
        }

        onRaid {
            sendMessage("Hello ${message.sourceDisplayName}! Thanks for the raid!")
        }
    }

    onConnected { join("mychannel") }
}

Installation

You can download this library from bintray

repositories {
    maven { url "https://dl.bintray.com/wooodenleg/maven" }
}

dependencies {
    implementation "com.tmik:TmiK-jvm:$version" // For JVM
    // OR
    implementation "com.tmik:TmiK-js:$version" // For JS
}