This commit is contained in:
2022-07-27 20:47:05 +02:00
parent d90cd88ed9
commit 76ad81a79a

View File

@@ -5,6 +5,7 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io" "io"
"os/exec"
"strings" "strings"
) )
@@ -17,6 +18,7 @@ Zdraví nově příchozí.
Příkazy: Příkazy:
!help - Zobraz nápovědu !help - Zobraz nápovědu
!pozdrav - pozdraví !pozdrav - pozdraví
!fortune - řekne moudrost
` `
) )
@@ -24,8 +26,8 @@ func sendMsg(conn io.Writer, msg string, receiver string) {
fmt.Fprintln(conn, "PRIVMSG "+receiver+" :"+msg) fmt.Fprintln(conn, "PRIVMSG "+receiver+" :"+msg)
} }
func sendHelp(conn io.Writer, receiver string) { func sendMultiline(conn io.Writer, msg string, receiver string) {
for _, l := range strings.Split(strings.Trim(help, "\n"), "\n") { for _, l := range strings.Split(strings.Trim(msg, "\n"), "\n") {
sendMsg(conn, l, receiver) sendMsg(conn, l, receiver)
} }
} }
@@ -59,14 +61,16 @@ func main() {
receiver = who receiver = who
} }
switch words[3][1:] { switch words[3][1:] {
case "!help":
sendMultiline(conn, help, receiver)
case "!pozdrav": case "!pozdrav":
sendMsg(conn, "Ahoj "+who, receiver) sendMsg(conn, "Ahoj "+who, receiver)
case "!help": case "!fortune":
sendHelp(conn, receiver) msg, _ := exec.Command("fortune").Output()
sendMultiline(conn, string(msg), receiver)
} }
} }
if words[0] == "PING" { if words[0] == "PING" {
fmt.Println("PONG")
fmt.Fprintln(conn, "PONG "+words[1]) fmt.Fprintln(conn, "PONG "+words[1])
} }
} }