pozdrav
This commit is contained in:
2022-07-26 17:45:51 +02:00
commit f0aab449ea
3 changed files with 55 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.swp
*.swo
irc_bot

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module irc_bot
go 1.18

49
irc_bot.go Normal file
View File

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