Giter VIP home page Giter VIP logo

tmik's Introduction

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
}

tmik's People

Contributors

mkpazon avatar wooodenleg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mkpazon

tmik's Issues

What is the proper way of making the app join a channel later

First off, I think you've done a really good job in this library. I'd really like to see this to be somewhat of a standard for TMI on Kotlin.

My use case is that I start the server but do not join a channel in onConnected right away. Another event triggers the joining of the channel (eg. an API call). What I have been doing is to store a reference of the mainscope so that later on I can use it to join a channel.

What if tmi(token) { ... } returns an object which exposes an API to join a channel?

 var mainScope: MainScope? = null

.
.
.

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

     onUserJoin {
         printlnWithThread("onUserJoin ${this.channel}: ${this.username}")
     }


   

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

    onConnected {
          // Do no thing.    <------------------ notice that I don't join the channel yet                           
    }
}
.
.
.
  suspend fun joinChannel(channel: String) = coroutineScope {
        launch {
            mainScope?.join(channel)
        }
    }

NumberFormatException in rawmessages after Twitch "predictions" has been introduced

A couple of days ago Twitch introduced Predictions . I am not entirely sure how it works, but what is clear is that it crashes the app due to a NumberFormatException. Here is an example RawMessage :

RawMessage(raw=@badge-info=predictions/Yes\si\sthink\sso,subscriber/11;badges=predictions/blue-1 ...)

It crashes in the badges bit blue-1 with a NumberFormatException

Here is the stacktrace:

java.lang.NumberFormatException: For input string: "blue-1"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:652)
    at java.lang.Integer.parseInt(Integer.java:770)
    at com.ktmi.tmi.messages.UtilityKt.parseTwitchPairSet(Utility.kt:52)
    at com.ktmi.tmi.messages.TwitchMessagesKt.get_badges(TwitchMessages.kt:41)
    at com.ktmi.tmi.messages.TwitchMessagesKt.access$get_badges$p(TwitchMessages.kt:1)
    at com.ktmi.tmi.messages.TextMessage.getBadges(TwitchMessages.kt:150)
    at com.ktmi.tmi.messages.TwitchMessagesKt.isSubscriber(TwitchMessages.kt:32)

[Intermittent] join(channel) sometimes does nothing

Several times when I call join(channel) to join a channel it doesn't do anything. This usually happens during development.

Does it ever happen that a bot stays in the channel even after your app has already closed? If it does, what happens if I try to join(channel) with a new session. Will the library allow it?

After waiting for a couple of minutes, joining becomes successful again.

Reconnect plugin in Kotlin/JS throws Exception

TmiK version:

0.0.5

Description:

Empty project with Reconnect plugin throws ReferenceError

Steps to reproduce:

  1. Create Kotlin/Js project with Node
  2. In main setup MainScope and add Reconnectplugin
tmi("oauth:token") {
  + Reconnect(10)
}

Stack trace:

ReferenceError: filterMessage$lambda is not defined
    at Coroutine$onTwitchMessage$lambda.doResume (C:\Users\Filip\Documents\wooodenbot-old\build\node_modules_imported\TmiK\TmiK.js:20405:29)
    at Coroutine$onTwitchMessage$lambda.CoroutineImpl.resumeWith_tl1gpc$ (C:\Users\Filip\Documents\wooodenbot-old\build\node_modules_imported\kotlin\kotlin.js:27964:35)
    at DispatchedContinuation.DispatchedTask.run (C:\Users\Filip\Documents\wooodenbot-old\build\node_modules_imported\kotlinx-coroutines-core\kotlinx-coroutines-core.js:2784:22)
    at NodeJsMessageQueue.MessageQueue.process (C:\Users\Filip\Documents\wooodenbot-old\build\node_modules_imported\kotlinx-coroutines-core\kotlinx-coroutines-core.js:30922:15)
    at C:\Users\Filip\Documents\wooodenbot-old\build\node_modules_imported\kotlinx-coroutines-core\kotlinx-coroutines-core.js:30873:27
    at process._tickCallback (internal/process/next_tick.js:61:11)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)

Sample on letting the bot join different channels

Does the library allow joining different channels?

Should I have a tmi(token = "...", context = this.coroutineContext) { ... } block for each channel I am joining or can I use the same tmi block?

Does not run in browser

browser.js?b00d:4 Uncaught Error: ws does not work in the browser. Browser clients must use the native WebSocket object
    at new module.exports (webpack-internal:///../../node_modules/ws/browser.js:4)
    at IRC.connect (webpack-internal:///./kotlin-dce-dev/TmiK.js:95329)
    at TmiClient.connect (webpack-internal:///./kotlin-dce-dev/TmiK.js:698)
    at eval (webpack-internal:///./kotlin-dce-dev/overlay.js:804)
    at eval (webpack-internal:///./kotlin-dce-dev/kotlin-wrappers-kotlin-react-js-legacy.js:804)
    at commitHookEffectListMount (webpack-internal:///../../node_modules/react-dom/cjs/react-dom.development.js:19731)
    at commitPassiveHookEffects (webpack-internal:///../../node_modules/react-dom/cjs/react-dom.development.js:19769)
    at HTMLUnknownElement.callCallback (webpack-internal:///../../node_modules/react-dom/cjs/react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (webpack-internal:///../../node_modules/react-dom/cjs/react-dom.development.js:237)
    at invokeGuardedCallback (webpack-internal:///../../node_modules/react-dom/cjs/react-dom.development.js:292)
    ```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.