forked from carrydela/mygoTgChanBot
增加功能:删除选择;相册转发
This commit is contained in:
@@ -17,12 +17,14 @@ const (
|
||||
)
|
||||
|
||||
type PostState struct {
|
||||
UserID int64
|
||||
ForwardedMsg *tele.Message
|
||||
SelectedCat string
|
||||
Title string
|
||||
Step PostStep
|
||||
CreatedAt time.Time
|
||||
UserID int64
|
||||
ForwardedMsg *tele.Message // 单条消息
|
||||
ForwardedMsgs []*tele.Message // 相册消息
|
||||
AlbumID string // 相册ID
|
||||
SelectedCat string
|
||||
Title string
|
||||
Step PostStep
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type StateManager struct {
|
||||
@@ -74,6 +76,51 @@ func (sm *StateManager) SetForwarded(userID int64, msg *tele.Message) *PostState
|
||||
}
|
||||
|
||||
state.ForwardedMsg = msg
|
||||
state.ForwardedMsgs = nil
|
||||
state.AlbumID = ""
|
||||
state.Step = StepAwaitCategory
|
||||
return state
|
||||
}
|
||||
|
||||
// AddAlbumMessage 添加相册消息,返回是否应该继续等待更多消息
|
||||
func (sm *StateManager) AddAlbumMessage(userID int64, msg *tele.Message) (shouldWait bool) {
|
||||
sm.mu.Lock()
|
||||
defer sm.mu.Unlock()
|
||||
|
||||
state := sm.states[userID]
|
||||
if state == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// 第一条相册消息
|
||||
if state.AlbumID == "" {
|
||||
state.AlbumID = msg.AlbumID
|
||||
state.ForwardedMsgs = []*tele.Message{msg}
|
||||
return true
|
||||
}
|
||||
|
||||
// 同一相册的后续消息
|
||||
if state.AlbumID == msg.AlbumID {
|
||||
state.ForwardedMsgs = append(state.ForwardedMsgs, msg)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// FinalizeAlbum 完成相册收集
|
||||
func (sm *StateManager) FinalizeAlbum(userID int64) *PostState {
|
||||
sm.mu.Lock()
|
||||
defer sm.mu.Unlock()
|
||||
|
||||
state := sm.states[userID]
|
||||
if state == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(state.ForwardedMsgs) > 0 {
|
||||
state.ForwardedMsg = state.ForwardedMsgs[0] // 用第一条提取标题
|
||||
}
|
||||
state.Step = StepAwaitCategory
|
||||
return state
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user