Remove Trailing param

This commit is contained in:
Daniel Oaks 2016-12-12 16:19:22 +10:00
parent 7af50d52b9
commit 0293a7f4a5
5 changed files with 69 additions and 67 deletions

View file

@ -179,7 +179,7 @@ func (c *Client) recv() {
switch msg.Command {
case Ping:
go c.write("PONG :" + msg.Trailing)
go c.write("PONG :" + msg.Params[len(msg.Params)-1])
case Join:
if msg.Nick == c.GetNick() {

View file

@ -5,11 +5,10 @@ import (
)
type Message struct {
Prefix string
Nick string
Command string
Params []string
Trailing string
Prefix string
Nick string
Command string
Params []string
}
func parseMessage(line string) *Message {
@ -31,9 +30,13 @@ func parseMessage(line string) *Message {
}
}
var usesTrailing bool
var trailing string
if i := strings.Index(line, " :"); i > 0 {
cmdEnd = i
msg.Trailing = line[i+2:]
trailing = line[i+2:]
usesTrailing = true
}
cmd := strings.Split(line[cmdStart:cmdEnd], " ")
@ -42,8 +45,8 @@ func parseMessage(line string) *Message {
msg.Params = cmd[1:]
}
if msg.Trailing != "" {
msg.Params = append(msg.Params, msg.Trailing)
if usesTrailing {
msg.Params = append(msg.Params, trailing)
}
return &msg

View file

@ -14,11 +14,10 @@ func TestParseMessage(t *testing.T) {
{
":user CMD #chan :some message\r\n",
&Message{
Prefix: "user",
Nick: "user",
Command: "CMD",
Params: []string{"#chan", "some message"},
Trailing: "some message",
Prefix: "user",
Nick: "user",
Command: "CMD",
Params: []string{"#chan", "some message"},
},
}, {
":nick!user@host.com CMD a b\r\n",
@ -32,7 +31,7 @@ func TestParseMessage(t *testing.T) {
"CMD a b :\r\n",
&Message{
Command: "CMD",
Params: []string{"a", "b"},
Params: []string{"a", "b", ""},
},
}, {
"CMD a b\r\n",
@ -48,9 +47,8 @@ func TestParseMessage(t *testing.T) {
}, {
"CMD :tests and stuff\r\n",
&Message{
Command: "CMD",
Params: []string{"tests and stuff"},
Trailing: "tests and stuff",
Command: "CMD",
Params: []string{"tests and stuff"},
},
}, {
":nick@host.com CMD\r\n",