3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-15 00:19:29 +01:00

Merge pull request #1904 from slingamn/prefix.1

bump irc-go to v0.1.0
This commit is contained in:
Shivaram Lingamneni 2022-01-20 18:03:25 -05:00 committed by GitHub
commit 6c0e9619cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 73 deletions

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/ergochat/confusables v0.0.0-20201108231250-4ab98ab61fb1
github.com/ergochat/go-ident v0.0.0-20200511222032-830550b1d775
github.com/ergochat/irc-go v0.0.0-20210617222258-256f1601d3ce
github.com/ergochat/irc-go v0.1.0
github.com/go-sql-driver/mysql v1.6.0
github.com/go-test/deep v1.0.6 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible

2
go.sum
View File

@ -12,6 +12,8 @@ github.com/ergochat/go-ident v0.0.0-20200511222032-830550b1d775 h1:QSJIdpr3HOzJD
github.com/ergochat/go-ident v0.0.0-20200511222032-830550b1d775/go.mod h1:d2qvgjD0TvGNSvUs+mZgX090RiJlrzUYW6vtANGOy3A=
github.com/ergochat/irc-go v0.0.0-20210617222258-256f1601d3ce h1:RfyjeynouKZjmnN8WGzCSrtuHGZ9dwfSYBq405FPoqs=
github.com/ergochat/irc-go v0.0.0-20210617222258-256f1601d3ce/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0=
github.com/ergochat/irc-go v0.1.0 h1:jBHUayERH9SiPOWe4ePDWRztBjIQsU/jwLbbGUuiOWM=
github.com/ergochat/irc-go v0.1.0/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0=
github.com/ergochat/scram v1.0.2-ergo1 h1:2bYXiRFQH636pT0msOG39fmEYl4Eq+OuutcyDsCix/g=
github.com/ergochat/scram v1.0.2-ergo1/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/ergochat/websocket v1.4.2-oragono1 h1:plMUunFBM6UoSCIYCKKclTdy/TkkHfUslhOfJQzfueM=

View File

@ -83,7 +83,7 @@ func (m *MessageCache) Initialize(server *Server, serverTime time.Time, msgid st
if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[command] {
msg.ForceTrailing()
}
msg.Prefix = nickmask
msg.Source = nickmask
msg.Command = command
msg.Params = make([]string, len(params))
copy(msg.Params, params)
@ -121,7 +121,7 @@ func (m *MessageCache) InitializeSplitMessage(server *Server, nickmask, accountN
msg.ForceTrailing()
}
msg.Prefix = nickmask
msg.Source = nickmask
msg.Command = command
if isTagmsg {
msg.Params = []string{target}
@ -146,7 +146,7 @@ func (m *MessageCache) InitializeSplitMessage(server *Server, nickmask, accountN
if forceTrailing {
msg.ForceTrailing()
}
msg.Prefix = nickmask
msg.Source = nickmask
msg.Command = command
msg.Params = make([]string, 2)
msg.Params[0] = target

View File

@ -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

View File

@ -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
View 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()
}

View File

@ -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 ""
// }

2
vendor/modules.txt vendored
View File

@ -16,7 +16,7 @@ github.com/ergochat/confusables
# github.com/ergochat/go-ident v0.0.0-20200511222032-830550b1d775
## explicit
github.com/ergochat/go-ident
# github.com/ergochat/irc-go v0.0.0-20210617222258-256f1601d3ce
# github.com/ergochat/irc-go v0.1.0
## explicit; go 1.15
github.com/ergochat/irc-go/ircfmt
github.com/ergochat/irc-go/ircmsg