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.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user