twitchirc

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 6 Imported by: 0

README

twitch-irc

Package to handle Twitch's IRC connection and message

Example

Import

  • go get github.com/fiuskylab/twitch-irc

package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"

	irc "github.com/fiuskylab/twitch-irc"
)

func main() {
	stop := make(chan os.Signal, 1)
	signal.Notify(stop, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

	cfg := irc.Config{
		OAuthToken:  "oauth:your_token",
		BotUsername: "bot_name",
		Channel:     "channel_name",
		MaxTries:    5,
	}

	client, err := irc.NewClient(&cfg)

	if err != nil {
		// handler error
		fmt.Println("Error!", err.Error())
	}

	for {
		select {
		case msg := <-client.Messages:
			fmt.Println(msg)
			// Can write messages with
			// client.Write("Hello, World!")
		case kill := <-stop:
			break
		}
	}
}

Documentation

Index

Constants

View Source
const (
	IRC_URL = "irc.chat.twitch.tv:6667"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Messages chan Message
	// contains filtered or unexported fields
}

Client is the IRC connector.

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient returns a Client instance

func (*Client) JoinChannel added in v0.1.3

func (c *Client) JoinChannel(name string) error

AddChannel connects the bot to a new channel

func (*Client) PartChannel added in v0.1.3

func (c *Client) PartChannel(name string) error

PartChannel leaves a Twitch's channel

func (*Client) SendMessage added in v0.1.3

func (c *Client) SendMessage(channel, msg string) error

SendMessage writes a message to a specifc IRC channel

func (*Client) Write

func (c *Client) Write(msg string) error

Write receives a string and write it into IRC TCP connection, don't need to add "\r\n" at the end of the string.

type Config

type Config struct {
	// OAuthToken is the token to allow you
	// to connect to the IRC.
	OAuthToken string

	// BotUsername must be the same as the account
	// that was used to generate the OAuthToken.
	BotUsername string

	// Channels are the names of a each Twitch's
	// channel that you want to your bot to connect to.
	Channels []string

	// MaxTries set de amount of times between
	// each connection retry.
	MaxTries uint
}

Config store the base information for a connection with Twitch's IRC.

type Message

type Message struct {
	// Channel is which channel the
	// message was sent
	Channel string
	// Sender the username of who sent
	// the Message
	Sender string
	// Text is the text sent to IRC
	Text string
	// contains filtered or unexported fields
}

Message refers to each line read in IRC connection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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