mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-02 22:20:41 +08:00
fix: ensure media group timeout is set to a minimum of 1 second during setup
This commit is contained in:
@@ -20,28 +20,32 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MediaGroupHandler struct {
|
type MediaGroupHandler struct {
|
||||||
groups map[int64][]tfile.TGFileMessage
|
groups map[int64][]tfile.TGFileMessage
|
||||||
timers map[int64]*time.Timer
|
timers map[int64]*time.Timer
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
setupOnce sync.Once
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MediaGroupHandler) SetupTimeout(timeoutSec int) {
|
||||||
|
m.setupOnce.Do(func() {
|
||||||
|
if timeoutSec < 1 {
|
||||||
|
timeoutSec = 1
|
||||||
|
}
|
||||||
|
m.timeout = time.Duration(timeoutSec) * time.Second
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
mediaGroupHandler *MediaGroupHandler
|
mediaGroupHandler = &MediaGroupHandler{
|
||||||
onceMediaGroup sync.Once
|
groups: make(map[int64][]tfile.TGFileMessage),
|
||||||
setupMediaGroupHandler = func() {
|
timers: make(map[int64]*time.Timer),
|
||||||
onceMediaGroup.Do(func() {
|
mu: sync.Mutex{},
|
||||||
mediaGroupHandler = &MediaGroupHandler{
|
|
||||||
groups: make(map[int64][]tfile.TGFileMessage),
|
|
||||||
timers: make(map[int64]*time.Timer),
|
|
||||||
timeout: time.Duration(max(config.C().Telegram.MediaGroupTimeout, 1)) * time.Second,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleGroupMediaMessage(ctx *ext.Context, update *ext.Update, message *tg.Message, groupID int64) error {
|
func handleGroupMediaMessage(ctx *ext.Context, update *ext.Update, message *tg.Message, groupID int64) error {
|
||||||
onceMediaGroup.Do(setupMediaGroupHandler)
|
mediaGroupHandler.SetupTimeout(max(config.C().Telegram.MediaGroupTimeout, 1))
|
||||||
logger := log.FromContext(ctx)
|
logger := log.FromContext(ctx)
|
||||||
media := message.Media
|
media := message.Media
|
||||||
supported := mediautil.IsSupported(media)
|
supported := mediautil.IsSupported(media)
|
||||||
|
|||||||
Reference in New Issue
Block a user