mirror of
https://gitlab.com/prokop_paruzek/botik.git
synced 2025-12-18 22:08:49 +01:00
init
pozdrav
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
irc_bot
|
||||||
49
irc_bot.go
Normal file
49
irc_bot.go
Normal 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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user