package irc import ( "fmt" "strconv" "strings" ) type ServerInfo struct { Users int Invisible int Channels int Servers int } func GetServerInfo(server, nick string) ServerInfo { users := 0 invis := 0 channels := 0 servers := 0 con := NewConnection(server, nick, nick, nil, nil) con.NumericCallback = func(from string, i int, args string) { switch i { case RPL_LUSERCLIENT: s := strings.Split(args, ":") if len(s) > 1 { fmt.Sscanf(s[1], "There are %d users and %d invisible on %d servers", &users, &invis, &servers) } case RPL_LUSERCHANNELS: s := strings.TrimSpace(strings.Split(args, " ")[1]) channels, _ = strconv.Atoi(s) con.SendQuit("") } } con.Run() return ServerInfo{ Users: users, Invisible: invis, Channels: channels, Servers: servers, } }