Files
plumber/internal/events/release.go
T
codegirl007 f96df3222d
CI / test (pull_request) Successful in 6m29s
Add video picker and Discord video attachments.
The picker accepts one MP4 or WebM, the thread lightbox zooms photos, and Discord gets the video as a file on a follow-up message so photo embeds still render.
2026-08-31 02:00:56 -07:00

42 lines
725 B
Go

package events
import (
"context"
"sync"
)
// Once returns fn wrapped so it runs at most once.
func Once(fn func()) func() {
if fn == nil {
return func() {}
}
var once sync.Once
return func() { once.Do(fn) }
}
// CallRelease runs Release on PostCreated or PostedToDiscord when set.
func CallRelease(ev any) {
switch e := ev.(type) {
case PostCreated:
if e.Release != nil {
e.Release()
}
case PostedToDiscord:
if e.Release != nil {
e.Release()
}
}
}
// SubscribeRelease runs PostedToDiscord.Release on the worker.
func SubscribeRelease(bus *Bus) {
if bus == nil {
return
}
bus.Subscribe(func(_ context.Context, ev any) {
if _, ok := ev.(PostedToDiscord); ok {
CallRelease(ev)
}
})
}