package main import ( "bufio" "crypto/tls" "fmt" "io" "strings" ) const ( host string = "pph21.duckdns.org:6697" help string = ` botík obecný Je v kanálu #test i v DM Zdraví nově příchozí. Příkazy: !help - Zobraz nápovědu !pozdrav - pozdraví ` ) func sendMsg(conn io.Writer, msg string, receiver string) { fmt.Fprintln(conn, "PRIVMSG "+receiver+" :"+msg) } func sendHelp(conn io.Writer, receiver string) { for _, l := range strings.Split(strings.Trim(help, "\n"), "\n") { sendMsg(conn, l, receiver) } } func main() { conn, err := tls.Dial("tcp", host, &tls.Config{RootCAs: nil}) if err != nil { panic("Failed to connect") } defer conn.Close() reader := bufio.NewReader(conn) fmt.Fprintln(conn, "PASS horal") fmt.Fprintln(conn, "USER bot rpi3 rpi3 :botik obecny") fmt.Fprintln(conn, "NICK botik") fmt.Fprintln(conn, "JOIN #test") for { in, _ := reader.ReadString('\n') words := strings.Fields(in) who := strings.Split(words[0], "!")[0][1:] if who == "botik" { continue } switch words[1] { case "JOIN": sendMsg(conn, "Vítej "+who, words[2]) case "PRIVMSG": var receiver string if []rune(words[2])[0] == '#' { receiver = words[2] } else { receiver = who } switch words[3][1:] { case "!pozdrav": sendMsg(conn, "Ahoj "+who, receiver) case "!help": sendHelp(conn, receiver) } } if words[0] == "PING" { fmt.Println("PONG") fmt.Fprintln(conn, "PONG "+words[1]) } } }