Add video picker and Discord video attachments.
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.
This commit is contained in:
2026-08-31 02:00:56 -07:00
parent 84dea8ea5d
commit f96df3222d
22 changed files with 1018 additions and 144 deletions
+28 -1
View File
@@ -2,6 +2,7 @@ package discord
import (
"context"
"strings"
"github.com/bwmarrin/discordgo"
)
@@ -63,14 +64,27 @@ func (s *sessionAPI) Close() error {
}
func toMessageSend(msg Message) *discordgo.MessageSend {
var files []*discordgo.File
for _, f := range msg.Files {
files = append(files, &discordgo.File{
Name: f.Name,
ContentType: f.ContentType,
Reader: f.Reader,
})
}
return &discordgo.MessageSend{
Content: messageContent(msg),
Embeds: toEmbeds(msg),
Files: files,
AllowedMentions: &discordgo.MessageAllowedMentions{},
}
}
func toEmbeds(msg Message) []*discordgo.MessageEmbed {
imageURLs := embedImageURLs(msg)
if msg.Title == "" && msg.Description == "" && msg.City == "" && msg.Author == "" && len(imageURLs) == 0 {
return nil
}
main := &discordgo.MessageEmbed{
Title: msg.Title,
URL: publicURL(msg.URL),
@@ -92,7 +106,7 @@ func toEmbeds(msg Message) []*discordgo.MessageEmbed {
})
}
embeds := []*discordgo.MessageEmbed{main}
for i, url := range msg.ImageURLs {
for i, url := range imageURLs {
if i == 0 {
main.Image = &discordgo.MessageEmbedImage{URL: url}
continue
@@ -104,3 +118,16 @@ func toEmbeds(msg Message) []*discordgo.MessageEmbed {
}
return embeds
}
func embedImageURLs(msg Message) []string {
var attached []string
for _, f := range msg.Files {
if strings.HasPrefix(f.ContentType, "image/") {
attached = append(attached, "attachment://"+f.Name)
}
}
if len(attached) > 0 {
return attached
}
return msg.ImageURLs
}