forked from External/ergo
bump irc-go to v0.1.0
This commit is contained in:
parent
fa7b76d66a
commit
74f3ea1d2e
7 changed files with 94 additions and 70 deletions
3
vendor/github.com/ergochat/irc-go/LICENSE
generated
vendored
3
vendor/github.com/ergochat/irc-go/LICENSE
generated
vendored
|
|
@ -1,4 +1,5 @@
|
|||
Copyright (c) 2016-2017 Daniel Oaks
|
||||
Copyright (c) 2016-2021 Daniel Oaks
|
||||
Copyright (c) 2018-2021 Shivaram Lingamneni
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
|
|
|||
38
vendor/github.com/ergochat/irc-go/ircmsg/message.go
generated
vendored
38
vendor/github.com/ergochat/irc-go/ircmsg/message.go
generated
vendored
|
|
@ -65,7 +65,7 @@ var (
|
|||
// extended by the IRCv3 Message Tags specification with the introduction
|
||||
// of message tags.
|
||||
type Message struct {
|
||||
Prefix string
|
||||
Source string
|
||||
Command string
|
||||
Params []string
|
||||
forceTrailing bool
|
||||
|
|
@ -154,6 +154,22 @@ func (msg *Message) ClientOnlyTags() map[string]string {
|
|||
return msg.clientOnlyTags
|
||||
}
|
||||
|
||||
// Nick returns the name component of the message source (typically a nickname,
|
||||
// but possibly a server name).
|
||||
func (msg *Message) Nick() (nick string) {
|
||||
nuh, err := ParseNUH(msg.Source)
|
||||
if err == nil {
|
||||
return nuh.Name
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NUH returns the source of the message as a parsed NUH ("nick-user-host");
|
||||
// if the source is not well-formed as a NUH, it returns an error.
|
||||
func (msg *Message) NUH() (nuh NUH, err error) {
|
||||
return ParseNUH(msg.Source)
|
||||
}
|
||||
|
||||
// ParseLine creates and returns a message from the given IRC line.
|
||||
func ParseLine(line string) (ircmsg Message, err error) {
|
||||
return parseLine(line, 0, 0)
|
||||
|
|
@ -229,15 +245,15 @@ func parseLine(line string, maxTagDataLength int, truncateLen int) (ircmsg Messa
|
|||
// by one or more ASCII SPACE characters"
|
||||
line = trimInitialSpaces(line)
|
||||
|
||||
// prefix
|
||||
// source
|
||||
if 0 < len(line) && line[0] == ':' {
|
||||
prefixEnd := strings.IndexByte(line, ' ')
|
||||
if prefixEnd == -1 {
|
||||
sourceEnd := strings.IndexByte(line, ' ')
|
||||
if sourceEnd == -1 {
|
||||
return ircmsg, ErrorLineIsEmpty
|
||||
}
|
||||
ircmsg.Prefix = line[1:prefixEnd]
|
||||
// skip over the prefix and the separating space
|
||||
line = line[prefixEnd+1:]
|
||||
ircmsg.Source = line[1:sourceEnd]
|
||||
// skip over the source and the separating space
|
||||
line = line[sourceEnd+1:]
|
||||
}
|
||||
|
||||
line = trimInitialSpaces(line)
|
||||
|
|
@ -312,8 +328,8 @@ func (ircmsg *Message) parseTags(tags string) (err error) {
|
|||
}
|
||||
|
||||
// MakeMessage provides a simple way to create a new Message.
|
||||
func MakeMessage(tags map[string]string, prefix string, command string, params ...string) (ircmsg Message) {
|
||||
ircmsg.Prefix = prefix
|
||||
func MakeMessage(tags map[string]string, source string, command string, params ...string) (ircmsg Message) {
|
||||
ircmsg.Source = source
|
||||
ircmsg.Command = command
|
||||
ircmsg.Params = params
|
||||
ircmsg.UpdateTags(tags)
|
||||
|
|
@ -411,9 +427,9 @@ func (ircmsg *Message) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagData
|
|||
return nil, ErrorTagsTooLong
|
||||
}
|
||||
|
||||
if len(ircmsg.Prefix) > 0 {
|
||||
if len(ircmsg.Source) > 0 {
|
||||
buf.WriteByte(':')
|
||||
buf.WriteString(ircmsg.Prefix)
|
||||
buf.WriteString(ircmsg.Source)
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
|
||||
|
|
|
|||
61
vendor/github.com/ergochat/irc-go/ircmsg/userhost.go
generated
vendored
Normal file
61
vendor/github.com/ergochat/irc-go/ircmsg/userhost.go
generated
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// written by Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the ISC license
|
||||
|
||||
package ircmsg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
MalformedNUH = errors.New("NUH is malformed")
|
||||
)
|
||||
|
||||
// NUH holds a parsed name!user@host source ("prefix") of an IRC message.
|
||||
// The Name member will be either a nickname (in the case of a user-initiated
|
||||
// message) or a server name (in the case of a server-initiated numeric,
|
||||
// command, or NOTICE).
|
||||
type NUH struct {
|
||||
Name string
|
||||
User string
|
||||
Host string
|
||||
}
|
||||
|
||||
// ParseNUH parses a NUH source of an IRC message into its constituent parts;
|
||||
// name (nickname or server name), username, and hostname.
|
||||
func ParseNUH(in string) (out NUH, err error) {
|
||||
if len(in) == 0 {
|
||||
return out, MalformedNUH
|
||||
}
|
||||
|
||||
hostStart := strings.IndexByte(in, '@')
|
||||
if hostStart != -1 {
|
||||
out.Host = in[hostStart+1:]
|
||||
in = in[:hostStart]
|
||||
}
|
||||
userStart := strings.IndexByte(in, '!')
|
||||
if userStart != -1 {
|
||||
out.User = in[userStart+1:]
|
||||
in = in[:userStart]
|
||||
}
|
||||
out.Name = in
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Canonical returns the canonical string representation of the NUH.
|
||||
func (nuh *NUH) Canonical() (result string) {
|
||||
var out strings.Builder
|
||||
out.Grow(len(nuh.Name) + len(nuh.User) + len(nuh.Host) + 2)
|
||||
out.WriteString(nuh.Name)
|
||||
if len(nuh.User) != 0 {
|
||||
out.WriteByte('!')
|
||||
out.WriteString(nuh.User)
|
||||
}
|
||||
if len(nuh.Host) != 0 {
|
||||
out.WriteByte('@')
|
||||
out.WriteString(nuh.Host)
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
56
vendor/github.com/ergochat/irc-go/ircutils/userhost.go
generated
vendored
56
vendor/github.com/ergochat/irc-go/ircutils/userhost.go
generated
vendored
|
|
@ -1,56 +0,0 @@
|
|||
// written by Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the ISC license
|
||||
|
||||
package ircutils
|
||||
|
||||
import "strings"
|
||||
|
||||
// UserHost holds a username+host combination
|
||||
type UserHost struct {
|
||||
Nick string
|
||||
User string
|
||||
Host string
|
||||
}
|
||||
|
||||
// ParseUserhost takes a userhost string and returns a UserHost instance.
|
||||
func ParseUserhost(userhost string) UserHost {
|
||||
var uh UserHost
|
||||
|
||||
if len(userhost) == 0 {
|
||||
return uh
|
||||
}
|
||||
|
||||
if strings.Contains(userhost, "!") {
|
||||
usersplit := strings.SplitN(userhost, "!", 2)
|
||||
var rest string
|
||||
if len(usersplit) == 2 {
|
||||
uh.Nick = usersplit[0]
|
||||
rest = usersplit[1]
|
||||
} else {
|
||||
rest = usersplit[0]
|
||||
}
|
||||
|
||||
hostsplit := strings.SplitN(rest, "@", 2)
|
||||
if len(hostsplit) == 2 {
|
||||
uh.User = hostsplit[0]
|
||||
uh.Host = hostsplit[1]
|
||||
} else {
|
||||
uh.User = hostsplit[0]
|
||||
}
|
||||
} else {
|
||||
hostsplit := strings.SplitN(userhost, "@", 2)
|
||||
if len(hostsplit) == 2 {
|
||||
uh.Nick = hostsplit[0]
|
||||
uh.Host = hostsplit[1]
|
||||
} else {
|
||||
uh.User = hostsplit[0]
|
||||
}
|
||||
}
|
||||
|
||||
return uh
|
||||
}
|
||||
|
||||
// // Canonical returns the canonical string representation of the userhost.
|
||||
// func (uh *UserHost) Canonical() string {
|
||||
// return ""
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue