package telegram import ( "sync" "time" tele "gopkg.in/telebot.v3" ) type PostStep int const ( StepAwaitForward PostStep = iota StepAwaitCategory StepAwaitConfirm ) type PostState struct { UserID int64 ForwardedMsg *tele.Message SelectedCat string Step PostStep CreatedAt time.Time } type StateManager struct { mu sync.RWMutex states map[int64]*PostState } func NewStateManager() *StateManager { return &StateManager{ states: make(map[int64]*PostState), } } func (sm *StateManager) Get(userID int64) *PostState { sm.mu.RLock() defer sm.mu.RUnlock() return sm.states[userID] } func (sm *StateManager) Set(state *PostState) { sm.mu.Lock() defer sm.mu.Unlock() sm.states[state.UserID] = state } func (sm *StateManager) Delete(userID int64) { sm.mu.Lock() defer sm.mu.Unlock() delete(sm.states, userID) } func (sm *StateManager) StartPost(userID int64) *PostState { state := &PostState{ UserID: userID, Step: StepAwaitForward, CreatedAt: time.Now(), } sm.Set(state) return state } func (sm *StateManager) SetForwarded(userID int64, msg *tele.Message) *PostState { sm.mu.Lock() defer sm.mu.Unlock() state := sm.states[userID] if state == nil { return nil } state.ForwardedMsg = msg state.Step = StepAwaitCategory return state } func (sm *StateManager) SetCategory(userID int64, category string) *PostState { sm.mu.Lock() defer sm.mu.Unlock() state := sm.states[userID] if state == nil { return nil } state.SelectedCat = category state.Step = StepAwaitConfirm return state }