CI / test (pull_request) Successful in 6m29s
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.
42 lines
725 B
Go
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)
|
|
}
|
|
})
|
|
}
|