-
Notifications
You must be signed in to change notification settings - Fork 1
TMI builder & Scopes
In the background TmiK communitaces with twitch using Websockets (as a internet protocol) and modified version of IRC (as a language of sorts). If you want to know more about Twitch messaging, visit their documentation. For ilustration a message received from Twitch IRC may look like this: @login=ronni;target-msg-id=abc-123-def :tmi.twitch.tv CLEARMSG #dallas :HeyGuys
TmiK uses DSL (Domain Specific Language) to make creating hierarchy of listeners easy. This hierarchy is composed using scopes. Each scope has the ability to transform messages going both down (received messages) and up (sent messages).
MainScope
is a root scope and holds reference to client (object communicating with Twitch using IRC). MainScope
exposes TwitchMessage
flow where we can listen to all incoming messages, connectionStatus
flow where IRC sends changes in internet connection and sendRaw()
function through which we can send messages back to Twitch. We will talk about other scopes later.
You don't have to use
MainScope
. You can create root scope of your own.
The MainScope
can be constructed via this builder function
tmi(token = "oauth:f00-8ar", username = "BotTob", secure = true, context = Dispatchers.IO) { //MainScope }
token (requiered) - this token identifies user that will be used to connect to Twitch IRC. You can get your token here
username (optional - defaults to "blank"
) - In documentation described as "...your Twitch username (login name) in lowercase" but it does not matter which username you will use (except one case) so this is optional parameter.
secure (optional - defaults to true
) - If true WSS (Web Socket Secure) protocol is used. Otherwise WS (unencrypted) protocol is used.
context (optional - defaults to Distaptchers.Default
) - CoroutineContext
that will be used for IRC communication and handling Flows
of TwitchMessages
block (requiered) - body of the builder where you will have access to MainScope
In MainScope
you will have access to all TwitchMessage
listeners and other scopes such as channel()
which will filter all messages inside the scope to be relevant to specified twitch channel or user()
which will do the same but with users.