func main() { flag.Parse() addr := fmt.Sprintf("%s:%v", *server, *port) c, err := irc.Dial(addr) if err != nil { fmt.Println(err) return } fmt.Printf("\n** For more information type `help` **\n\n") defer c.Close() quit := make(chan bool) c.ToSend <- "NICK " + *nick c.ToSend <- "USER bot * * :..." // irc messages reader go func() { for { select { case err := <-c.Error: fmt.Println("client read error", err) quit <- true return case msg := <-c.Received: if bytes.Equal(msg.Command, []byte("PRIVMSG")) { fmt.Printf("%s:: %s %s -> %s\n", msg.Command, msg.Params, msg.Prefix, msg.Trailing) } else { fmt.Println("> ", msg.String()) } } } }() // user input reader go func() { in := bufio.NewReader(os.Stdin) for { data, err := in.ReadString('\n') if err != nil { fmt.Sprintf("client write error: %s", err) return } data = strings.TrimSpace(data) switch data { case "help": fmt.Println(help) case "quit": quit <- true default: c.ToSend <- data } } }() <-quit }
func main() { flag.Parse() addr := fmt.Sprintf("%s:%v", *server, *port) c, err := irc.Dial(addr) if err != nil { fmt.Println(err) return } send := func(s string) { fmt.Println("> " + s) c.ToSend <- s } pm := &PMod{ ircchan: "pmodtesting", players: make(map[string]*Player), } quit := make(chan bool) send("NICK " + *modnick) send("USER ircctest * * :Ed Cashin") send("JOIN #" + pm.ircchan) // irc messages reader go func() { for { select { case err := <-c.Error: fmt.Println("client read error", err) quit <- true return case msg := <-c.Received: if msg != nil { s := msg.String() fmt.Println("< ", s) if !pm.handle(send, s) { return } } else { return } } } }() // user input reader go func() { in := bufio.NewReader(os.Stdin) for { data, err := in.ReadString('\n') if err != nil { fmt.Sprintf("client write error: %s", err) return } data = strings.TrimSpace(data) switch data { case "quit": send("QUIT :bye") quit <- true default: send(data) } } }() <-quit }