commit f0aab449ea6089d1d5fcec6be49504bba3a2f648 Author: prokopparuzek Date: Tue Jul 26 17:45:51 2022 +0200 init pozdrav diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d834bba --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +*.swo +irc_bot diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1f750a5 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module irc_bot + +go 1.18 diff --git a/irc_bot.go b/irc_bot.go new file mode 100644 index 0000000..f891e33 --- /dev/null +++ b/irc_bot.go @@ -0,0 +1,49 @@ +package main + +import ( + "bufio" + "crypto/tls" + "fmt" + "strings" +) + +const ( + host string = "pph21.duckdns.org:6697" +) + +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": + fmt.Fprintln(conn, "PRIVMSG "+words[2]+" :VĂ­tej "+who) + case "PRIVMSG": + if words[3] == ":!pozdrav" { + if []rune(words[2])[0] == '#' { + fmt.Fprintln(conn, "PRIVMSG "+words[2]+" :Ahoj "+who) + } else { + fmt.Fprintln(conn, "PRIVMSG "+who+" :Ahoj "+who) + } + } + } + if words[0] == "PING" { + fmt.Println("PONG") + fmt.Fprintln(conn, "PONG "+words[1]) + } + } +}