This commit is contained in:
2022-07-27 21:22:23 +02:00
parent 76ad81a79a
commit f6626d5c72
2 changed files with 15 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ import (
"io"
"os/exec"
"strings"
"github.com/icelain/jokeapi"
)
const (
@@ -19,6 +21,7 @@ Příkazy:
!help - Zobraz nápovědu
!pozdrav - pozdraví
!fortune - řekne moudrost
!ftip - poví vtip
`
)
@@ -33,6 +36,7 @@ func sendMultiline(conn io.Writer, msg string, receiver string) {
}
func main() {
// IRC init
conn, err := tls.Dial("tcp", host, &tls.Config{RootCAs: nil})
if err != nil {
panic("Failed to connect")
@@ -43,6 +47,10 @@ func main() {
fmt.Fprintln(conn, "USER bot rpi3 rpi3 :botik obecny")
fmt.Fprintln(conn, "NICK botik")
fmt.Fprintln(conn, "JOIN #test")
// joke init
api := jokeapi.New()
api.SetLang("en")
// IRC
for {
in, _ := reader.ReadString('\n')
words := strings.Fields(in)
@@ -68,6 +76,11 @@ func main() {
case "!fortune":
msg, _ := exec.Command("fortune").Output()
sendMultiline(conn, string(msg), receiver)
case "!ftip":
ftip, _ := api.Fetch()
for _, l := range ftip.Joke {
sendMultiline(conn, l, receiver)
}
}
}
if words[0] == "PING" {