114 lines
2.6 KiB
Go
114 lines
2.6 KiB
Go
package irc
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
channel = "#warez"
|
|
)
|
|
|
|
func TestJoinChannel(t *testing.T) {
|
|
con := NewConnection("irc.ouch.chat:6667", "irc-go", "irc-go", nil, []string{channel})
|
|
|
|
go con.Run()
|
|
|
|
time.Sleep(5 * time.Second)
|
|
log.Printf("%d users in channel %s\n", len(con.userList[channel]), channel)
|
|
con.SendQuit("scan complete")
|
|
|
|
//con.SendPrivmsg("#warez", fmt.Sprintf("\x0356 FUCK YALL BITCHES %d", len(con.userList["#warez"])))
|
|
|
|
/*
|
|
i := 0
|
|
for _, v := range con.userList[channel] {
|
|
con.SendPrivmsg(channel, fmt.Sprintf("yo %s fuck you", v))
|
|
if i >= 5 {
|
|
time.Sleep(1000 * time.Millisecond)
|
|
i = 0
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
|
|
func TestLusers(t *testing.T) {
|
|
con := NewConnection("irc.ouch.chat:6667", "irc-go", "irc-go", nil, []string{channel})
|
|
|
|
con.NumericCallback = func(from string, i int, args string) {
|
|
if i == RPL_LUSERCLIENT {
|
|
con.SendJoin(channel)
|
|
|
|
s := strings.Split(args, ":")
|
|
if len(s) > 1 {
|
|
users := 0
|
|
invis := 0
|
|
servers := 0
|
|
fmt.Sscanf(s[1], "There are %d users and %d invisible on %d servers", &users, &invis, &servers)
|
|
con.SendPrivmsg(channel, fmt.Sprintf("total users on network: %d, invisible %d, servers %d", users, invis, servers))
|
|
}
|
|
con.SendQuit("scan complete")
|
|
}
|
|
}
|
|
|
|
con.Run()
|
|
}
|
|
|
|
func TestLusersChannels(t *testing.T) {
|
|
con := NewConnection("irc.ouch.chat:6667", "irc-go", "irc-go", nil, []string{channel})
|
|
|
|
con.NumericCallback = func(from string, i int, args string) {
|
|
if i == RPL_LUSERCHANNELS {
|
|
con.SendJoin(channel)
|
|
|
|
s := strings.TrimSpace(strings.Split(args, " ")[1])
|
|
val, err := strconv.Atoi(s)
|
|
if err == nil {
|
|
con.SendPrivmsg(channel, fmt.Sprintf("There are %d channels formed", val))
|
|
} else {
|
|
t.Fatal(err.Error())
|
|
}
|
|
con.SendQuit("scan complete")
|
|
}
|
|
}
|
|
|
|
con.Run()
|
|
}
|
|
|
|
func TestMultiClient(t *testing.T) {
|
|
con := NewConnection("irc.ouch.chat:6667", "irc-go", "irc-go", nil, []string{channel})
|
|
|
|
chancnt := make(chan int)
|
|
|
|
con.NumericCallback = func(from string, i int, args string) {
|
|
if i == RPL_ENDOFMOTD {
|
|
con2 := NewConnection("irc.libera.chat:6667", "irc-go66543", "irc-go66543", nil, nil)
|
|
con2.NumericCallback = func(from string, i int, args string) {
|
|
if i == RPL_LUSERCHANNELS {
|
|
s := strings.TrimSpace(strings.Split(args, " ")[1])
|
|
val, _ := strconv.Atoi(s)
|
|
chancnt <- val
|
|
}
|
|
}
|
|
go con2.Run()
|
|
|
|
go func() {
|
|
resp := <-chancnt
|
|
con.SendPrivmsg(channel, fmt.Sprintf("There are %d channels formed on libera", resp))
|
|
con2.SendQuit("")
|
|
con.SendQuit("")
|
|
}()
|
|
}
|
|
}
|
|
|
|
con.Run()
|
|
}
|
|
|
|
func TestParser(t *testing.T) {
|
|
log.Printf("testing %s\n", t.Name())
|
|
}
|