valera/internal/states/start_bot_state/start_bot_state.go

46 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-04-08 11:55:16 +00:00
package start_bot_state
import (
"fmt"
"net/http"
"valera/internal/db"
"valera/internal/states"
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
"golang.org/x/exp/slices"
)
var names = []string{
"/start",
}
type startBotState struct {
bot *tgbot.BotAPI
dataBase *db.DB
version string
}
func NewStartBotState(bot *tgbot.BotAPI, dataBase *db.DB, version string) states.BotState {
return &startBotState{
bot: bot,
dataBase: dataBase,
version: version,
}
}
2023-04-09 07:47:38 +00:00
func (s *startBotState) Do(text string, chatInfo *db.ChatInfo) error {
2023-04-08 11:55:16 +00:00
if !slices.Contains(names, text) {
return nil
}
msg := fmt.Sprintf("Здорова, я Валера (%s), твой тренер (%d).", s.version, chatInfo.ChatID)
_, _ = s.bot.Send(tgbot.NewMessage(chatInfo.ChatID, msg))
return s.dataBase.SetStatusToChat(chatInfo.ChatID, db.UserStateNone)
}
func (s *startBotState) GetHandler() (string, func(http.ResponseWriter, *http.Request)) {
return names[0], func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
}
}