add /start and /ping commands

This commit is contained in:
Владимир Фёдоров 2022-04-03 17:19:32 +07:00
parent 7078778d39
commit de70ca6e91
2 changed files with 18 additions and 0 deletions

8
commands/command.go Normal file
View File

@ -0,0 +1,8 @@
package commands
type Command string
const (
Start = Command("/start")
Ping = Command("/ping")
)

10
main.go
View File

@ -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"))
}
} }
} }