@@ -0,0 +1,44 @@
|
||||
package clear_bot_state
|
||||
|
||||
import (
|
||||
"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{
|
||||
"/c", // en
|
||||
"/с", // ru
|
||||
}
|
||||
|
||||
type clearBotState struct {
|
||||
bot *tgbot.BotAPI
|
||||
dataBase *db.DB
|
||||
}
|
||||
|
||||
func NewClearBotState(bot *tgbot.BotAPI, dataBase *db.DB) states.BotState {
|
||||
return &clearBotState{
|
||||
bot: bot,
|
||||
dataBase: dataBase,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *clearBotState) Do(text string, chatInfo *db.ChatInfo, username string) error {
|
||||
if !slices.Contains(names, text) {
|
||||
return nil
|
||||
}
|
||||
|
||||
msg := tgbot.NewMessage(chatInfo.ChatID, "Чистка")
|
||||
msg.ReplyMarkup = tgbot.NewRemoveKeyboard(false)
|
||||
_, _ = s.bot.Send(msg)
|
||||
return s.dataBase.SetStatusToChat(chatInfo.ChatID, db.UserStateNone)
|
||||
}
|
||||
|
||||
func (s *clearBotState) 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