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