Documentation ¶
Overview ¶
Package ircmsg helps parse and create lines for IRC connections.
Index ¶
- Constants
- Variables
- func EscapeTagValue(inString string) string
- func UnescapeTagValue(inString string) string
- type Message
- func (msg *Message) AllTags() (result map[string]string)
- func (msg *Message) ClientOnlyTags() map[string]string
- func (msg *Message) DeleteTag(tagName string)
- func (msg *Message) ForceTrailing()
- func (msg *Message) GetTag(tagName string) (present bool, value string)
- func (msg *Message) HasTag(tagName string) (present bool)
- func (ircmsg *Message) Line() (result string, err error)
- func (ircmsg *Message) LineBytes() (result []byte, err error)
- func (ircmsg *Message) LineBytesStrict(fromClient bool, truncateLen int) ([]byte, error)
- func (msg *Message) SetTag(tagName, tagValue string)
- func (msg *Message) UpdateTags(tags map[string]string)
Constants ¶
const ( // "The size limit for message tags is 8191 bytes, including the leading // '@' (0x40) and trailing space ' ' (0x20) characters." MaxlenTags = 8191 // MaxlenTags - ('@' + ' ') MaxlenTagData = MaxlenTags - 2 // "Clients MUST NOT send messages with tag data exceeding 4094 bytes, // this includes tags with or without the client-only prefix." MaxlenClientTagData = 4094 // "Servers MUST NOT add tag data exceeding 4094 bytes to messages." MaxlenServerTagData = 4094 // '@' + MaxlenClientTagData + ' ' // this is the analogue of MaxlenTags when the source of the message is a client MaxlenTagsFromClient = MaxlenClientTagData + 2 )
Variables ¶
var ( // ErrorLineIsEmpty indicates that the given IRC line was empty. ErrorLineIsEmpty = errors.New("Line is empty") // ErrorLineContainsBadChar indicates that the line contained invalid characters ErrorLineContainsBadChar = errors.New("Line contains invalid characters") // ErrorBodyTooLong indicates that the message body exceeded the specified // length limit (typically 512 bytes). This error is non-fatal; if encountered // when parsing a message, the message is parsed up to the length limit, and // if encountered when serializing a message, the message is truncated to the limit. ErrorBodyTooLong = errors.New("Line body exceeded the specified length limit; outgoing messages will be truncated") // ErrorTagsTooLong indicates that the message exceeded the maximum tag length // (the specified response on the server side is 417 ERR_INPUTTOOLONG). ErrorTagsTooLong = errors.New("Line could not be processed because its tag data exceeded the length limit") // ErrorInvalidTagContent indicates that a tag name or value was invalid ErrorInvalidTagContent = errors.New("Line could not be processed because it contained an invalid tag name or value") // ErrorCommandMissing indicates that an IRC message was invalid because it lacked a command. ErrorCommandMissing = errors.New("IRC messages MUST have a command") // ErrorBadParam indicates that an IRC message could not be serialized because // its parameters violated the syntactic constraints on IRC parameters: // non-final parameters cannot be empty, contain a space, or start with `:`. ErrorBadParam = errors.New("Cannot have an empty param, a param with spaces, or a param that starts with ':' before the last parameter") )
Functions ¶
func EscapeTagValue ¶
EscapeTagValue takes a value, and returns an escaped message tag value.
This function is automatically used when lines are created from an Message, so you don't need to call it yourself before creating a line.
func UnescapeTagValue ¶
UnescapeTagValue takes an escaped message tag value, and returns the raw value.
This function is automatically used when lines are interpreted by ParseLine, so you don't need to call it yourself after parsing a line.
Types ¶
type Message ¶
type Message struct { Prefix string Command string Params []string // contains filtered or unexported fields }
Message represents an IRC message, as defined by the RFCs and as extended by the IRCv3 Message Tags specification with the introduction of message tags.
func MakeMessage ¶
func MakeMessage(tags map[string]string, prefix string, command string, params ...string) (ircmsg Message)
MakeMessage provides a simple way to create a new Message.
func ParseLineStrict ¶
ParseLineStrict creates and returns an Message from the given IRC line, taking the maximum length into account and truncating the message as appropriate. If fromClient is true, it enforces the client limit on tag data length (4094 bytes), allowing the server to return ERR_INPUTTOOLONG as appropriate. If truncateLen is nonzero, it is the length at which the non-tag portion of the message is truncated.
func (*Message) ClientOnlyTags ¶
ClientOnlyTags returns the client-only tags (the tags with the + prefix). The returned map may be internal storage of the Message object and should not be modified.
func (*Message) ForceTrailing ¶
func (msg *Message) ForceTrailing()
ForceTrailing ensures that when the message is serialized, the final parameter will be encoded as a "trailing parameter" (preceded by a colon). This is almost never necessary and should not be used except when having to interact with broken implementations that don't correctly interpret IRC messages.
func (*Message) LineBytesStrict ¶
LineBytesStrict returns a sendable line, as a []byte, created from an Message. fromClient controls whether the server-side or client-side tag length limit is enforced. If truncateLen is nonzero, it is the length at which the non-tag portion of the message is truncated.
func (*Message) UpdateTags ¶
UpdateTags is a convenience to set multiple tags at once.