refactor
This commit is contained in:
@@ -12,6 +12,10 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var emptyKeyboard = echotron.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]echotron.InlineKeyboardButton{},
|
||||
}
|
||||
|
||||
type Exec struct {
|
||||
handled bool
|
||||
transitioned bool
|
||||
@@ -77,23 +81,17 @@ func (b *Bot) GetOrCreateJWT(u *echotron.Update) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Запрашиваем JWT с актуальными данными пользователя (или создаем нового если не существует)
|
||||
jwt, err := b.Backend.GetJWTByTelegramUser(
|
||||
context.Background(),
|
||||
b.ChatID,
|
||||
username,
|
||||
firstName,
|
||||
lastName,
|
||||
)
|
||||
jwt, err := b.Backend.GetJWTByTelegramUser(context.Background(), b.ChatID, username, firstName, lastName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Сохраняем в сессию
|
||||
b.Session.JWT = jwt
|
||||
if username != nil {
|
||||
b.Session.UserName = *username
|
||||
|
||||
if firstName != nil {
|
||||
b.Session.FirstName = *firstName
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -276,7 +274,11 @@ func (b *Bot) Update(u *echotron.Update) {
|
||||
return
|
||||
}
|
||||
|
||||
_ = b.GetOrCreateJWT(u)
|
||||
err := b.GetOrCreateJWT(u)
|
||||
if err != nil || b.Session.JWT == "" {
|
||||
b.SendNew("❌ Ошибка авторизации. Попробуйте /start", emptyKeyboard)
|
||||
return
|
||||
}
|
||||
|
||||
exec := &Exec{}
|
||||
b.exec = exec
|
||||
@@ -336,10 +338,6 @@ func (b *Bot) Update(u *echotron.Update) {
|
||||
}
|
||||
|
||||
func (b *Bot) cleanupKeyboard(messageID int) {
|
||||
emptyKeyboard := echotron.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]echotron.InlineKeyboardButton{},
|
||||
}
|
||||
|
||||
_, err := b.EditMessageReplyMarkup(
|
||||
echotron.NewMessageID(b.ChatID, messageID),
|
||||
&echotron.MessageReplyMarkupOptions{ReplyMarkup: emptyKeyboard},
|
||||
|
||||
@@ -17,6 +17,6 @@ type State interface {
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
UserName string
|
||||
JWT string
|
||||
FirstName string
|
||||
JWT string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user