-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_command.go
54 lines (45 loc) · 1.35 KB
/
login_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package command
import (
_ "embed"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joomcode/errorx"
"github.com/mih-kopylov/our-spb-bot/internal/bot"
"github.com/mih-kopylov/our-spb-bot/internal/bot/form"
"github.com/mih-kopylov/our-spb-bot/internal/bot/service"
"github.com/mih-kopylov/our-spb-bot/internal/state"
)
const (
LoginCommandName = "login"
)
type LoginCommand struct {
states state.States
service *service.Service
}
func NewLoginCommand(states state.States, service *service.Service) bot.Command {
return &LoginCommand{
states: states,
service: service,
}
}
func (c *LoginCommand) Name() string {
return LoginCommandName
}
func (c *LoginCommand) Description() string {
return "Авторизация на портале"
}
func (c *LoginCommand) Handle(message *tgbotapi.Message) error {
userState, err := c.states.GetState(message.Chat.ID)
if err != nil {
return errorx.EnhanceStackTrace(err, "failed to get user state")
}
userState.MessageHandlerName = form.LoginFormName
err = c.states.SetState(userState)
if err != nil {
return errorx.EnhanceStackTrace(err, "failed to set user state")
}
err = c.service.SendMessage(message.Chat, "Введите логин от аккаунта на портале")
if err != nil {
return errorx.EnhanceStackTrace(err, "failed to send reply")
}
return nil
}