irc/irc_helpers.go
blackbeard420 eef648ac56
All checks were successful
continuous-integration/drone/push Build is passing
added GetServerInfo shortcut
2021-10-27 21:49:24 -04:00

47 lines
823 B
Go

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,
}
}