mirror of
https://gitlab.com/prokop_paruzek/botik.git
synced 2025-12-19 14:27:58 +01:00
help
uprava kodu
This commit is contained in:
32
irc_bot.go
32
irc_bot.go
@@ -4,13 +4,32 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
host string = "pph21.duckdns.org:6697"
|
host string = "pph21.duckdns.org:6697"
|
||||||
|
help string = `
|
||||||
|
botík obecný
|
||||||
|
Je v kanálu #test i v DM
|
||||||
|
Zdraví nově příchozí.
|
||||||
|
Příkazy:
|
||||||
|
!help - Zobraz nápovědu
|
||||||
|
!pozdrav - pozdraví
|
||||||
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func sendMsg(conn io.Writer, msg string, receiver string) {
|
||||||
|
fmt.Fprintln(conn, "PRIVMSG "+receiver+" :"+msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendHelp(conn io.Writer, receiver string) {
|
||||||
|
for _, l := range strings.Split(strings.Trim(help, "\n"), "\n") {
|
||||||
|
sendMsg(conn, l, receiver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
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 {
|
||||||
@@ -31,14 +50,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
switch words[1] {
|
switch words[1] {
|
||||||
case "JOIN":
|
case "JOIN":
|
||||||
fmt.Fprintln(conn, "PRIVMSG "+words[2]+" :Vítej "+who)
|
sendMsg(conn, "Vítej "+who, words[2])
|
||||||
case "PRIVMSG":
|
case "PRIVMSG":
|
||||||
if words[3] == ":!pozdrav" {
|
var receiver string
|
||||||
if []rune(words[2])[0] == '#' {
|
if []rune(words[2])[0] == '#' {
|
||||||
fmt.Fprintln(conn, "PRIVMSG "+words[2]+" :Ahoj "+who)
|
receiver = words[2]
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(conn, "PRIVMSG "+who+" :Ahoj "+who)
|
receiver = who
|
||||||
}
|
}
|
||||||
|
switch words[3][1:] {
|
||||||
|
case "!pozdrav":
|
||||||
|
sendMsg(conn, "Ahoj "+who, receiver)
|
||||||
|
case "!help":
|
||||||
|
sendHelp(conn, receiver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if words[0] == "PING" {
|
if words[0] == "PING" {
|
||||||
|
|||||||
Reference in New Issue
Block a user