mirror of
https://gitlab.com/prokop_paruzek/botik.git
synced 2025-12-19 06:17:56 +01:00
fortune
This commit is contained in:
14
irc_bot.go
14
irc_bot.go
@@ -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])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user