2023-07-09 01:28:59 +03:00
|
|
|
package behx
|
|
|
|
|
2023-07-12 14:06:05 +03:00
|
|
|
import (
|
|
|
|
apix "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Update = apix.Update
|
|
|
|
|
2023-07-09 01:28:59 +03:00
|
|
|
// Represents unique value to identify chats.
|
|
|
|
// In fact is simply ID of the chat.
|
|
|
|
type SessionId int64
|
|
|
|
|
|
|
|
// The type represents current state of
|
|
|
|
// user interaction per each of them.
|
|
|
|
type Session struct {
|
2023-07-12 14:06:05 +03:00
|
|
|
// Unique identifier for the session, Telegram chat's ID.
|
2023-07-09 01:28:59 +03:00
|
|
|
Id SessionId
|
2023-07-12 14:06:05 +03:00
|
|
|
// Current screen identifier.
|
2023-07-09 01:28:59 +03:00
|
|
|
CurrentScreenId ScreenId
|
2023-07-12 14:06:05 +03:00
|
|
|
// ID of the previous screen.
|
2023-07-09 01:28:59 +03:00
|
|
|
PreviousScreenId ScreenId
|
2023-07-12 14:06:05 +03:00
|
|
|
// The currently showed on display keyboard.
|
2023-07-12 02:02:33 +03:00
|
|
|
KeyboardId KeyboardId
|
2023-07-12 14:59:07 +03:00
|
|
|
|
|
|
|
// Custom data for each user.
|
|
|
|
V map[string] any
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// The type represents map of sessions using
|
|
|
|
// as key.
|
|
|
|
type SessionMap map[SessionId] *Session
|
|
|
|
|
2023-07-12 14:06:05 +03:00
|
|
|
// Return new empty session with
|
|
|
|
func NewSession(id SessionId) *Session {
|
|
|
|
return &Session{
|
|
|
|
Id: id,
|
2023-07-12 14:59:07 +03:00
|
|
|
V: make(map[string] any),
|
2023-07-12 14:06:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Changes screen of user to the Id one for the session.
|
|
|
|
func (c *Session) ChangeScreen(screenId ScreenId) {
|
|
|
|
c.PreviousScreenId = c.CurrentScreenId
|
|
|
|
c.CurrentScreenId = screenId
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the SessionId to Telegram API's type.
|
2023-07-12 00:33:51 +03:00
|
|
|
func (si SessionId) ToTelegram() int64 {
|
|
|
|
return int64(si)
|
|
|
|
}
|
|
|
|
|
2023-07-12 14:06:05 +03:00
|
|
|
// Add new empty session by it's ID.
|
2023-07-12 00:33:51 +03:00
|
|
|
func (sm SessionMap) Add(sid SessionId) {
|
2023-07-12 14:06:05 +03:00
|
|
|
sm[sid] = NewSession(sid)
|
2023-07-12 00:33:51 +03:00
|
|
|
}
|