twitch_chat

package module
v0.1.1-0...-6d621cc Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 4 Imported by: 0

README

twitch-live-chat-downloader

Twitch chat feed without any authentication

How does it work?

  • Simply mimics the Websocket connection

Install

go get -u github.com/abhinavxd/twitch-live-chat-downloader

Getting started

package main

import (
	"fmt"
	"log"

	"github.com/abhinavxd/twitch-live-chat-downloader"
)

// twitch channel name from URL-  https://www.twitch.tv/aceu
const CHANNEL_NAME = "aceu"

func main() {
	// Open a websocket connection to twitch chat
	// Call this function again to reconnect
	err := twitch_chat.InitializeConnection(CHANNEL_NAME)
	if err != nil {
		log.Fatal(err)
	}

	for {
		message, err := twitch_chat.FetchMessages()
		
		if err != nil {
			log.Println(err)
			// Reconnect websocket connection
			err := twitch_chat.InitializeConnection(CHANNEL_NAME)
			if err != nil {
				log.Println(err)
			}
			continue
		}

		// Optionally you can Parse IRC tags which returns a `Message`
		// Or you can use the IRC tags directly
		parsedMsg, err := twitch_chat.ParseTags(message)
		
		if err != nil {
			log.Println(err)
			continue
		}

		fmt.Printf("%+v\n\n", parsedMsg)
	}
}

Screenshot from 2022-01-01 15-44-34

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Documentation

Index

Constants

View Source
const (
	TWITCH_NICK         = "justinfan28165"
	TWITCH_WS_URL       = "irc-ws.chat.twitch.tv"
	PASS                = "SCHMOOPIIE"
	USER_TYPE_SEPERATOR = "PRIVMSG #"
)

Variables

View Source
var (
	// https://ircv3.net/specs/extensions/message-tags.html
	IRC_MSG_TAGS = []string{"subscriber", "user-id", "user-type", "mod", "tmi-sent-ts", "display-name", "reply-parent-msg-body", "reply-parent-user-login", "system-msg", "msg-param-recipient-user-name", "msg-param-recipient-display-name", "msg-param-gift-months", "msg-param-months", "msg-id"}
)

Functions

func FetchMessages

func FetchMessages() (string, error)

func InitializeConnection

func InitializeConnection(channel_name string) error

Opens a websocket connection to twitch chat Call this function again to reconnect

Types

type Message

type Message struct {
	// Username of user sending message
	Username string
	// Actual chat message
	Message string
	// if the user is subscriber or not
	Subscriber string
	// id of user sending message
	UserId string
	// timestamp in milliseconds
	Timestamp string
	// message to which this message is a reply
	ReplyTo string
	// username of user to whom this message is a reply
	ReplyToUser string
	// if the user is mod or not
	Mod string
	// System messages are messages by twitch
	// These include gifted subs and other actions
	SystemMsg string
	// Recipient of sub gift or other action
	MsgParamRecipientUsername string
	// Recipient display name
	MsgParamRecipientDisplayName string
	// Number of months of gifted sub
	MsgParamGiftMonths string
	// Number of months
	MsgParamMonths string
	// msg-id=subgift means gifted sub
	MsgId string
}

func ParseTags

func ParseTags(tagsB string) (Message, error)

Parse twitch IRC tags and return a `Message` Example of IRC tags in new ws message-

@badge-info=;badges=;client-nonce=3b6178753cbb5d5654e546105f1b3714;color=#009EC3; display-name=killertrip7;emotes=;first-msg=0;flags=;id=ec1296ae-c5f2-4eec-bf88-74b0088689fb;mod=0; room-id=26490481;subscriber=0;tmi-sent-ts=1641025567523;turbo=0;user-id=64035912; user-type= :killertrip7!killertrip7@killertrip7.tmi.twitch.tv PRIVMSG #summit1g :!p wing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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