Skip to content

glotchimo/glisten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
    }
}

About

Twitch chat bot framework for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages