@@ -0,0 +1,45 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *startBotState) Do(text string, chatInfo *db.ChatInfo, username string) error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user