Files
botik/irc_bot.go
2022-07-26 17:45:51 +02:00

50 lines
1.0 KiB
Go

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])
}
}
}