irc

package
v0.0.0-...-55a1825 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package irc implements basic scanning and formatting of IRC messages.

While package irc is designed for Twitch.TV IRC, it should be able to handle any valid RFC 1459 messages plus IRCv3 tags. The focus is on simplicity, universality, and performance, rather than convenience. Users should be familiar with RFC 1459.

This package does not handle IRC connections. It can parse messages from an existing IRC connection via an io.RuneScanner wrapper, such as bufio.Reader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Malformed

type Malformed struct {
	// contains filtered or unexported fields
}

Malformed indicates a malformed IRC message.

func (Malformed) Error

func (err Malformed) Error() string

type Message

type Message struct {
	// Time is the time at which the message was sent.
	Time time.Time
	// Tags is the full tags component of the received message. Use the Tag
	// method to get the parsed, unquoted value of a single tag.
	Tags string
	// Sender is identifying information of the user or server that sent the
	// message.
	Sender
	// Command is the message command or numeric response code.
	Command string
	// Params is the "middle" parameters of the message.
	Params []string
	// Trailing is the "trailing" parameter of the message.
	Trailing string
}

Message represents a single Twitch IRC Message.

func Parse

func Parse(scan io.RuneScanner) (msg Message, err error)

Parse parses a message.

func Privmsg

func Privmsg(to, message string) Message

Privmsg is a shortcut to create a PRIVMSG message for sending.

func Whisper

func Whisper(to, message string) Message

Whisper is a shortcut to create a Twitch whisper to a given user.

func (Message) Badges

func (m Message) Badges(v []string) []string

Badges appends the list of Twitch badges, parsed from the badges tag and without versions, to v and returns v.

func (Message) DisplayName

func (m Message) DisplayName() string

DisplayName returns a display name for the message sender. If the message has a non-empty display-name tag, then this returns that; otherwise, it returns the sender's nick.

func (Message) ForeachTag

func (m Message) ForeachTag(f func(key, value string))

ForeachTag calls f for each tag on m. Tag values are unquoted and may be the empty string.

func (Message) Reply

func (m Message) Reply(format string, args ...interface{}) Message

Reply creates an appropriately-targeted response to a PRIVMSG or WHISPER. Panics if the message type is neither PRIVMSG nor WHISPER. The message is formatted according to the rules of fmt.Sprintf.

func (Message) String

func (m Message) String() string

String formats the message as an IRC message string appropriate for sending to an IRC server, not including the ending CR LF sequence. This does not perform any validation.

func (Message) Tag

func (m Message) Tag(name string) (val string, ok bool)

Tag retrieves a tag by name. ok is false if and only if the tag is not present.

func (Message) Text

func (m Message) Text() string

Text formats the message as a short display string.

func (Message) To

func (m Message) To() string

To returns m.Params[0]. Panics if m.Params is empty.

Notably, this identifies the channel or user a PRIVMSG message is sent to.

type Sender

type Sender struct {
	// Nick is the nickname of the user who produced the message, or the
	// hostname of the server for messages not produced by users.
	Nick string
	// User is the username of the user who produced the message, if any. For
	// Twitch IRC, this is always the same as Nick if it is nonempty.
	User string
	// Host is the hostname of the user who produced the message, if any. For
	// Twitch IRC, this is always "tmi.twitch.tv" or "<user>.tmi.twitch.tv",
	// where <user> is the username of the authenticated client.
	Host string
}

Sender is a message Sender. It may represent a user or server.

func (Sender) String

func (s Sender) String() string

String formats the sender as "nick!user@host". Separators are omitted for empty fields where valid.

Jump to

Keyboard shortcuts

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