Documentation
¶
Overview ¶
Package ircmsg parses raw irc messages.
The Message and Prefix structs provide translation to and from raw IRC messages:
// Parse the IRC-encoded data and store the result in a new struct: message := ircmsg.ParseMessage(raw) // Translate back to a raw IRC message string: raw = message.String()
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Message ¶
Message represents an IRC protocol message. See RFC1459 section 2.3.1.
<message> ::= [':' <prefix> <SPACE> ] <command> <params> <crlf>
<prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
<command> ::= <letter> { <letter> } | <number> <number> <number>
<SPACE> ::= ' ' { ' ' }
<params> ::= <SPACE> [ ':' <trailing> | <middle> <params> ]
<middle> ::= <Any *non-empty* sequence of octets not including SPACE
or NUL or CR or LF, the first of which may not be ':'>
<trailing> ::= <Any, possibly *empty*, sequence of octets not including
NUL or CR or LF>
<crlf> ::= CR LF
func ParseMessage ¶
ParseMessage takes a string and attempts to create a Message struct. Returns nil if the Message is invalid.
Example ¶
message := ParseMessage("JOIN #help")
fmt.Println(message.Params[0])
Output: #help
func (*Message) Bytes ¶
Bytes returns a []byte representation of this message.
As noted in rfc2812 section 2.3, messages should not exceed 512 characters in length. This method forces that limit by discarding any characters exceeding the length limit.
func (*Message) Param ¶
Param returns the i'th parameter. Returns the empty string if the requested parameter does not exist.
func (*Message) String ¶
String returns a string representation of this message.
As noted in rfc2812 section 2.3, messages should not exceed 512 characters in length. This method forces that limit by discarding any characters exceeding the length limit.
Example ¶
message := &Message{
Prefix: &Prefix{
Name: "sorcix",
User: "sorcix",
Host: "myhostname",
},
Command: "PRIVMSG",
Params: []string{"This is an example!"},
}
fmt.Println(message.String())
Output: :sorcix!sorcix@myhostname PRIVMSG :This is an example!
type Prefix ¶
type Prefix struct {
Name string // Nick- or servername
User string // Username
Host string // Hostname
}
Prefix represents the prefix (sender) of an IRC message. See RFC1459 section 2.3.1.
<servername> | <nick> [ '!' <user> ] [ '@' <host> ]
func ParsePrefix ¶
ParsePrefix takes a string and attempts to create a Prefix struct.
func (*Prefix) IsHostmask ¶
IsHostmask returns true if this prefix looks like a user hostmask.
type Tags ¶
Tags represents (optional) tags added to the start of each message See IRCv3.2 Message Tags (http://ircv3.net/specs/core/message-tags-3.2.html)
<message> ::= ['@' <tags> <SPACE>] [':' <prefix> <SPACE> ] <command> <params> <crlf> <tags> ::= <tag> [';' <tag>]* <tag> ::= <key> ['=' <escaped value>] <key> ::= [ <vendor> '/' ] <sequence of letters, digits, hyphens (`-`)> <escaped value> ::= <sequence of any characters except NUL, CR, LF, semicolon (`;`) and SPACE> <vendor> ::= <host>