add /start and /ping commands
This commit is contained in:
parent
7078778d39
commit
de70ca6e91
|
@ -0,0 +1,8 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
type Command string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Start = Command("/start")
|
||||||
|
Ping = Command("/ping")
|
||||||
|
)
|
10
main.go
10
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"git.user-penguin.space/vladimir/all_tg_bot/commands"
|
||||||
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
|
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"github.com/umputun/go-flags"
|
"github.com/umputun/go-flags"
|
||||||
"log"
|
"log"
|
||||||
|
@ -16,6 +17,7 @@ const (
|
||||||
|
|
||||||
type Opts struct {
|
type Opts struct {
|
||||||
Token string `short:"t" long:"token" description:"Telegram api token"`
|
Token string `short:"t" long:"token" description:"Telegram api token"`
|
||||||
|
Name string `short:"n" long:"name" description:"Telegram bot name" default:"@butler_tg_bot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts Opts
|
var opts Opts
|
||||||
|
@ -59,5 +61,13 @@ func run() {
|
||||||
if strings.Contains(strings.ToLower(text), tag) {
|
if strings.Contains(strings.ToLower(text), tag) {
|
||||||
_, _ = bot.Send(tgbot.NewMessage(chatID, allUsers))
|
_, _ = bot.Send(tgbot.NewMessage(chatID, allUsers))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command := commands.Command(strings.Replace(text, opts.Name, "", 1))
|
||||||
|
switch command {
|
||||||
|
case commands.Start:
|
||||||
|
_, _ = bot.Send(tgbot.NewMessage(chatID, "Здравствуйте, я ваш дворецкий."))
|
||||||
|
case commands.Ping:
|
||||||
|
_, _ = bot.Send(tgbot.NewMessage(chatID, "pong"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue