Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 1.51 KB

README.md

File metadata and controls

60 lines (47 loc) · 1.51 KB

glisten

A simple Go framework for building command-driven Twitch chat bots.

Usage

Full examples can be found in examples, but we will walk through the essentials here.

The first step is creating a new bot with glisten.NewBot. This method requires some options for authenticating with Twitch.

bot, err := glisten.NewBot(&glisten.BotOptions{
    Channel: "some channel",
    Username: "some username",
    Password: "some password",
})
if err != nil {
    log.Fatal("error creating new bot: ", err)
}

Note that you can make a bot password using this implicit grant flow implementation.

Once the bot's ready, the next step is handler registration using. Handler functions use a specific signature (func (m glisten.Message) glisten.Event) and are registered using the bot.AddHandler method.

bot.AddHandler("!timer", func(m glisten.Message) glisten.Event {
    // ... do some stuff
    return Event{ ... }
}

After we've added all our handlers, we go ahead and start the connection and listening process. Note that the Bot.Connect method is blocking and should be launched in a goroutine.

go bot.Connect()

Once we see a confirmation message in the browser tab and the program's logs, we know we're ready to start listening for events. There are two important channels to watch: bot.Events and bot.Errors.

for {
    select {
    case event := <-bot.Events:
        // ... handle events
    case error := <-bot.Errors:
        // ... handle errors
    }
}