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 IrcMessage
- func (msg *IrcMessage) AllTags() (result map[string]string)
- func (msg *IrcMessage) ClientOnlyTags() map[string]string
- func (msg *IrcMessage) DeleteTag(tagName string)
- func (msg *IrcMessage) GetTag(tagName string) (present bool, value string)
- func (msg *IrcMessage) HasTag(tagName string) (present bool)
- func (ircmsg *IrcMessage) Line() (result string, err error)
- func (ircmsg *IrcMessage) LineBytes() (result []byte, err error)
- func (ircmsg *IrcMessage) LineBytesStrict(fromClient bool, truncateLen int) ([]byte, error)
- func (msg *IrcMessage) SetTag(tagName, tagValue string)
- func (msg *IrcMessage) 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") // ErrorLineTooLong indicates that the message exceeded the maximum tag length // (the name references 417 ERR_INPUTTOOLONG; we reserve the right to return it // for messages that exceed the non-tag length limit) ErrorLineTooLong = errors.New("Line could not be parsed because a specified length limit was exceeded") ErrorCommandMissing = errors.New("IRC messages MUST have a command") 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 IrcMessage, 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 IrcMessage ¶
type IrcMessage struct { Prefix string Command string Params []string // contains filtered or unexported fields }
IrcMessage 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 IrcMessage)
MakeMessage provides a simple way to create a new IrcMessage.
func ParseLine ¶
func ParseLine(line string) (ircmsg IrcMessage, err error)
ParseLine creates and returns a message from the given IRC line.
func ParseLineStrict ¶
func ParseLineStrict(line string, fromClient bool, truncateLen int) (ircmsg IrcMessage, err error)
ParseLineStrict creates and returns an IrcMessage 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 (*IrcMessage) AllTags ¶
func (msg *IrcMessage) AllTags() (result map[string]string)
AllTags returns all tags as a single map.
func (*IrcMessage) ClientOnlyTags ¶
func (msg *IrcMessage) ClientOnlyTags() map[string]string
ClientOnlyTags returns the client-only tags (the tags with the + prefix). The returned map may be internal storage of the IrcMessage object and should not be modified.
func (*IrcMessage) DeleteTag ¶
func (msg *IrcMessage) DeleteTag(tagName string)
DeleteTag deletes a tag.
func (*IrcMessage) GetTag ¶
func (msg *IrcMessage) GetTag(tagName string) (present bool, value string)
GetTag returns whether a tag is present, and if so, what its value is.
func (*IrcMessage) HasTag ¶
func (msg *IrcMessage) HasTag(tagName string) (present bool)
HasTag returns whether a tag is present.
func (*IrcMessage) Line ¶
func (ircmsg *IrcMessage) Line() (result string, err error)
Line returns a sendable line created from an IrcMessage.
func (*IrcMessage) LineBytes ¶
func (ircmsg *IrcMessage) LineBytes() (result []byte, err error)
LineBytes returns a sendable line created from an IrcMessage.
func (*IrcMessage) LineBytesStrict ¶
func (ircmsg *IrcMessage) LineBytesStrict(fromClient bool, truncateLen int) ([]byte, error)
LineBytesStrict returns a sendable line, as a []byte, created from an IrcMessage. 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 (*IrcMessage) SetTag ¶
func (msg *IrcMessage) SetTag(tagName, tagValue string)
SetTag sets a tag.
func (*IrcMessage) UpdateTags ¶
func (msg *IrcMessage) UpdateTags(tags map[string]string)
UpdateTags is a convenience to set multiple tags at once.