mirror of
https://gitlab.com/prokop_paruzek/botik.git
synced 2025-12-19 06:17:56 +01:00
ftip
This commit is contained in:
2
go.mod
2
go.mod
@@ -1,3 +1,5 @@
|
|||||||
module irc_bot
|
module irc_bot
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
require github.com/icelain/jokeapi v0.0.0-20220428143244-f71f87248478
|
||||||
|
|||||||
13
irc_bot.go
13
irc_bot.go
@@ -7,6 +7,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/icelain/jokeapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -19,6 +21,7 @@ Příkazy:
|
|||||||
!help - Zobraz nápovědu
|
!help - Zobraz nápovědu
|
||||||
!pozdrav - pozdraví
|
!pozdrav - pozdraví
|
||||||
!fortune - řekne moudrost
|
!fortune - řekne moudrost
|
||||||
|
!ftip - poví vtip
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,6 +36,7 @@ func sendMultiline(conn io.Writer, msg string, receiver string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// IRC init
|
||||||
conn, err := tls.Dial("tcp", host, &tls.Config{RootCAs: nil})
|
conn, err := tls.Dial("tcp", host, &tls.Config{RootCAs: nil})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Failed to connect")
|
panic("Failed to connect")
|
||||||
@@ -43,6 +47,10 @@ func main() {
|
|||||||
fmt.Fprintln(conn, "USER bot rpi3 rpi3 :botik obecny")
|
fmt.Fprintln(conn, "USER bot rpi3 rpi3 :botik obecny")
|
||||||
fmt.Fprintln(conn, "NICK botik")
|
fmt.Fprintln(conn, "NICK botik")
|
||||||
fmt.Fprintln(conn, "JOIN #test")
|
fmt.Fprintln(conn, "JOIN #test")
|
||||||
|
// joke init
|
||||||
|
api := jokeapi.New()
|
||||||
|
api.SetLang("en")
|
||||||
|
// IRC
|
||||||
for {
|
for {
|
||||||
in, _ := reader.ReadString('\n')
|
in, _ := reader.ReadString('\n')
|
||||||
words := strings.Fields(in)
|
words := strings.Fields(in)
|
||||||
@@ -68,6 +76,11 @@ func main() {
|
|||||||
case "!fortune":
|
case "!fortune":
|
||||||
msg, _ := exec.Command("fortune").Output()
|
msg, _ := exec.Command("fortune").Output()
|
||||||
sendMultiline(conn, string(msg), receiver)
|
sendMultiline(conn, string(msg), receiver)
|
||||||
|
case "!ftip":
|
||||||
|
ftip, _ := api.Fetch()
|
||||||
|
for _, l := range ftip.Joke {
|
||||||
|
sendMultiline(conn, l, receiver)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if words[0] == "PING" {
|
if words[0] == "PING" {
|
||||||
|
|||||||
Reference in New Issue
Block a user