twitch

package module
v0.0.0-...-c49c943 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2021 License: MIT Imports: 9 Imported by: 1

README

go-twitch-ws

I wanted to build a Twitch Bouncer in Go but I was missing the Websocket interface I only found this: https://github.com/gempir/go-twitch-irc I also build my own light variant for the twitch-websockets interface

Help/Ideas/Improvements from

Twitch Docs Getting started with websocket client in go go-twitch-irc recws irc-message parser tmi.js twitch-js

Documentation

https://pkg.go.dev/github.com/spddl/go-twitch-ws

Getting Started

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)

bot, err := twitch.NewClient(twitch.Client{
  Server:      "wss://irc-ws.chat.twitch.tv", // SSL, without SSL: ws://irc-ws.chat.twitch.tv
  User:        "",
  Oauth:       "", // without "oauth:" https://twitchapps.com/tmi/
  Debug:       true,
  BotVerified: false, // verified bots: Have higher chat limits than regular users.
  Channel: []string{"gronkhtv", "tfue", "dreamhackcs"}, // only in Lowercase
})
if err != nil {
  panic(err)
}

bot.OnPrivateMessage = func(msg twitch.IRCMessage) {
  channel := msg.Params[0][1:] // to remove # from Channel Parameter
  msgline := msg.Params[1]

  if bytes.Equal(channel, []byte("#spddl")) {
    if bytes.Contains(msgline, []byte("hi")) {
      bot.Say("spddl", "Hi!", false) // only with creds
    }
  }
  log.Println(fmt.Sprintf("%s - %s: %s", msg.Params[0][1:], msg.Tags["display-name"], msg.Params[1]))
}

bot.Run()

for { // ctrl - c
  <-interrupt
  bot.Close()
  os.Exit(0)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Server      string
	User        string
	Oauth       string
	Debug       bool
	BotVerified bool
	BotKnown    bool
	Channel     []string

	OnConnect               func(message bool)
	OnPrivateMessage        func(message IRCMessage)
	OnRoomStateMessage      func(message IRCMessage)
	OnHosttargetMessage     func(message IRCMessage)
	OnNoticeMessage         func(message IRCMessage)
	OnJoinMessage           func(message IRCMessage)
	OnPartMessage           func(message IRCMessage)
	OnUnknownMessage        func(message IRCMessage)
	OnUserNoticeMessage     func(message IRCMessage)
	OnClearMsgMessage       func(message IRCMessage)
	OnClearChatMessage      func(message IRCMessage)
	OnGlobalUserSateMessage func(message IRCMessage)
	OnUserStateMessage      func(message IRCMessage)
	OnNamesMessage          func(message IRCMessage)
	OnEndOfNamesMessage     func(message IRCMessage)
	OnWhisperMessage        func(message IRCMessage)
	OnPongLatency           func(message time.Duration)
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c *Client) (*Client, error)

func (*Client) Close

func (c *Client) Close()

Close closes the underlying network connection without sending or waiting for a close frame.

func (*Client) CloseAndReconnect

func (c *Client) CloseAndReconnect()

CloseAndReconnect will try to reconnect.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns the WebSocket connection state

func (*Client) Join

func (c *Client) Join(channels []string)

Join accept channels only in lowercase

func (*Client) Part

func (c *Client) Part(channels []string)

Part accept channels only in lowercase

func (*Client) Run

func (c *Client) Run()

func (*Client) Say

func (c *Client) Say(channel, msg string, modPrivileged bool)

Say channel without #

func (*Client) Whisper

func (c *Client) Whisper(nick, msg string)

type EmitQueue

type EmitQueue struct {
	Authenticate        chan string
	Join                chan string
	RateLimit           chan string
	ModOp               chan string
	Whisper             chan string
	WhisperKnownBot     chan string
	WhisperVerifiedBots chan string
}

type IRCMessage

type IRCMessage struct {
	Raw     []byte
	Tags    map[string][]byte
	Command []byte
	Params  [][]byte
	Prefix  []byte
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL