项目作者: dimorinny

项目描述 :
High level Twitch chat abstraction
高级语言: Go
项目地址: git://github.com/dimorinny/twitch-chat-api.git
创建时间: 2017-02-25T22:04:32Z
项目社区:https://github.com/dimorinny/twitch-chat-api

开源协议:

下载


High level Twitch chat abstraction

This library provide high level wrapper above Twitch (IRC) API, that allow you analyze stream comments and building Twitch bots.

Installation

  1. go get github.com/dimorinny/twitch-chat-api

Configuration

Create configuration object:

  1. config = twitchchat.NewConfiguration(
  2. nickname,
  3. oauth,
  4. channel,
  5. )

You can quickly get a oauth token for your account with this helpful page.
For more information you should read official Twitch IRC documentation.

Usage

Ferstly, you need to create chat object like this:

  1. twitch := twitchchat.NewChat(config)

For receiving chat status (like connected, disconnected, new message) you can use 2 ways:

Using callbacks api

  1. stop := make(chan struct{})
  2. defer close(stop)
  3. err := twitch.ConnectWithCallbacks(
  4. func() {
  5. fmt.Println("Connected")
  6. },
  7. func() {
  8. fmt.Println("Disconnected")
  9. stop <- struct{}{}
  10. },
  11. func(message string) {
  12. fmt.Println(message)
  13. },
  14. )
  15. if err != nil {
  16. return
  17. }
  18. <-stop

Using channels api

  1. stop := make(chan struct{})
  2. defer close(stop)
  3. disconnected := make(chan struct{})
  4. connected := make(chan struct{})
  5. message := make(chan string)
  6. go func() {
  7. for {
  8. select {
  9. case <-disconnected:
  10. fmt.Println("Disconnected")
  11. stop <- struct{}{}
  12. case <-connected:
  13. fmt.Println("Connected")
  14. case newMessage := <-message:
  15. fmt.Println(newMessage)
  16. }
  17. }
  18. }()
  19. if err := twitch.ConnectWithChannels(connected, disconnected, message); err != nil {
  20. return
  21. }
  22. <-stop

For more complicated usage example see sample code.