Browse Source

fix query messages' echoes not being put in right target (for real this time).

master
Gisle Aune 4 years ago
parent
commit
773cde9c26
  1. 7
      client.go
  2. 9
      client_test.go
  3. 39
      event_packet_test.go
  4. 2
      go.mod

7
client.go

@ -1361,9 +1361,12 @@ func (client *Client) handleEvent(event *Event) {
// Target the message
target := Target(client.status)
targetName := event.Arg(0)
if targetName == client.Nick() {
targetName = event.Nick
}
if targetName == client.nick {
queryTarget := client.Target("query", event.Nick)
if event.Nick == client.nick || event.Arg(0) == client.nick {
queryTarget := client.Target("query", targetName)
if queryTarget == nil {
query := &Query{
id: client.id,

9
client_test.go

@ -249,8 +249,11 @@ func TestClient(t *testing.T) {
}},
{Client: "PRIVMSG SevenAsterisks :hi!"},
{Server: ":Test768!~Tester@127.0.0.1 PRIVMSG SevenAsterisks :hi!"},
{Server: "PING :testserver.example.com"}, // Ping/Pong to sync.
{Client: "PONG :testserver.example.com"},
{Callback: func() error {
event := logger.Last("packet", "PRIVMSG")
if event == nil {
return errors.New("did not find last query message")
}
@ -260,6 +263,12 @@ func TestClient(t *testing.T) {
if event.QueryTarget().Name() != "SevenAsterisks" {
return errors.New("incorrect query target")
}
if event.Nick != client.Nick() {
return errors.New("incorrect client nick")
}
if event.Arg(0) != "SevenAsterisks" {
return errors.New("incorrect client nick")
}
return nil
}},

39
event_packet_test.go

@ -0,0 +1,39 @@
package irc_test
import (
"github.com/gissleh/irc"
"github.com/stretchr/testify/assert"
"testing"
)
type packetTestRow struct {
Data string
Kind string
Verb string
Args []string
Text string
Tags map[string]string
}
var packetTestTable = []packetTestRow{
{":test.server PING Test", "packet", "PING", []string{"Test"}, "", map[string]string{}},
{":test.server PING :Test", "packet", "PING", []string{}, "Test", map[string]string{}},
{":Test2!test@test.example.com PRIVMSG Tester :\x01ACTION hello to you.\x01", "ctcp", "ACTION", []string{"Tester"}, "hello to you.", map[string]string{}},
}
func TestParsePacket(t *testing.T) {
for _, row := range packetTestTable {
t.Run(row.Data, func(t *testing.T) {
event, err := irc.ParsePacket(row.Data)
if err != nil {
t.Error("Parse Failed", err)
return
}
assert.Equal(t, row.Kind, event.Kind(), "kind")
assert.Equal(t, row.Verb, event.Verb(), "kind")
assert.Equal(t, row.Args, event.Args, "kind")
assert.Equal(t, row.Text, event.Text, "kind")
})
}
}

2
go.mod

@ -1,3 +1,5 @@
module github.com/gissleh/irc
go 1.12
require github.com/stretchr/testify v1.6.1
Loading…
Cancel
Save