mirror of
https://github.com/gissleh/irc.git
synced 2026-10-02 08:35:35 +00:00
migrate to github, add stuff.
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.aiterp.net/gisle/irc"
|
||||
"github.com/gissleh/irc"
|
||||
)
|
||||
|
||||
// AssertUserlist compares the userlist to a list of prefixed nicks
|
||||
|
||||
@@ -49,58 +49,49 @@ func (interaction *Interaction) Listen() (addr string, err error) {
|
||||
for i := 0; i < len(lines); i++ {
|
||||
line := lines[i]
|
||||
|
||||
if line.Data != "" {
|
||||
switch line.Kind {
|
||||
case 'S':
|
||||
{
|
||||
_, err := conn.Write(append([]byte(line.Data), '\r', '\n'))
|
||||
if err != nil {
|
||||
interaction.Failure = &InteractionFailure{
|
||||
Index: i, NetErr: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
case 'C':
|
||||
{
|
||||
conn.SetReadDeadline(time.Now().Add(time.Second * 2))
|
||||
input, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
interaction.Failure = &InteractionFailure{
|
||||
Index: i, NetErr: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
input = strings.Replace(input, "\r", "", -1)
|
||||
input = strings.Replace(input, "\n", "", 1)
|
||||
|
||||
match := line.Data
|
||||
success := false
|
||||
|
||||
if strings.HasSuffix(match, "*") {
|
||||
success = strings.HasPrefix(input, match[:len(match)-1])
|
||||
} else {
|
||||
success = match == input
|
||||
}
|
||||
|
||||
interaction.Log = append(interaction.Log, input)
|
||||
|
||||
if !success {
|
||||
if !interaction.Strict {
|
||||
i--
|
||||
continue
|
||||
}
|
||||
|
||||
interaction.Failure = &InteractionFailure{
|
||||
Index: i, Result: input,
|
||||
}
|
||||
return
|
||||
}
|
||||
if line.Server != "" {
|
||||
_, err := conn.Write(append([]byte(line.Server), '\r', '\n'))
|
||||
if err != nil {
|
||||
interaction.Failure = &InteractionFailure{
|
||||
Index: i, NetErr: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
} else if line.Client != "" {
|
||||
conn.SetReadDeadline(time.Now().Add(time.Second * 2))
|
||||
input, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
interaction.Failure = &InteractionFailure{
|
||||
Index: i, NetErr: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
input = strings.Replace(input, "\r", "", -1)
|
||||
input = strings.Replace(input, "\n", "", 1)
|
||||
|
||||
if line.Callback != nil {
|
||||
match := line.Client
|
||||
success := false
|
||||
|
||||
if strings.HasSuffix(match, "*") {
|
||||
success = strings.HasPrefix(input, match[:len(match)-1])
|
||||
} else {
|
||||
success = match == input
|
||||
}
|
||||
|
||||
interaction.Log = append(interaction.Log, input)
|
||||
|
||||
if !success {
|
||||
if !interaction.Strict {
|
||||
i--
|
||||
continue
|
||||
}
|
||||
|
||||
interaction.Failure = &InteractionFailure{
|
||||
Index: i, Result: input,
|
||||
}
|
||||
return
|
||||
}
|
||||
} else if line.Callback != nil {
|
||||
err := line.Callback()
|
||||
if err != nil {
|
||||
interaction.Failure = &InteractionFailure{
|
||||
@@ -132,7 +123,7 @@ type InteractionFailure struct {
|
||||
// InteractionLine is part of an interaction, whether it is a line
|
||||
// that is sent to a client or a line expected from a client.
|
||||
type InteractionLine struct {
|
||||
Kind byte
|
||||
Data string
|
||||
Client string
|
||||
Server string
|
||||
Callback func() error
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"git.aiterp.net/gisle/irc/internal/irctest"
|
||||
"github.com/gissleh/irc/internal/irctest"
|
||||
)
|
||||
|
||||
func TestInteraction(t *testing.T) {
|
||||
interaction := irctest.Interaction{
|
||||
Lines: []irctest.InteractionLine{
|
||||
{Kind: 'C', Data: "FIRST MESSAGE"},
|
||||
{Kind: 'S', Data: "SERVER MESSAGE"},
|
||||
{Kind: 'C', Data: "SECOND MESSAGE"},
|
||||
{Client: "FIRST MESSAGE"},
|
||||
{Server: "SERVER MESSAGE"},
|
||||
{Client: "SECOND MESSAGE"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user