Refactor post handling and add command setup for Telegram bot
This commit is contained in:
@@ -12,6 +12,7 @@ type PostStep int
|
||||
const (
|
||||
StepAwaitForward PostStep = iota
|
||||
StepAwaitCategory
|
||||
StepAwaitTitle
|
||||
StepAwaitConfirm
|
||||
)
|
||||
|
||||
@@ -19,6 +20,7 @@ type PostState struct {
|
||||
UserID int64
|
||||
ForwardedMsg *tele.Message
|
||||
SelectedCat string
|
||||
Title string
|
||||
Step PostStep
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -86,6 +88,20 @@ func (sm *StateManager) SetCategory(userID int64, category string) *PostState {
|
||||
}
|
||||
|
||||
state.SelectedCat = category
|
||||
state.Step = StepAwaitTitle
|
||||
return state
|
||||
}
|
||||
|
||||
func (sm *StateManager) SetTitle(userID int64, title string) *PostState {
|
||||
sm.mu.Lock()
|
||||
defer sm.mu.Unlock()
|
||||
|
||||
state := sm.states[userID]
|
||||
if state == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
state.Title = title
|
||||
state.Step = StepAwaitConfirm
|
||||
return state
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user