Live video on the AT Protocol
at natb/sentry 57 lines 1.9 kB view raw
1package webhook 2 3import ( 4 "context" 5 "fmt" 6 7 "github.com/bluesky-social/indigo/api/bsky" 8 "stream.place/streamplace/pkg/integrations/discord" 9 "stream.place/streamplace/pkg/integrations/discord/discordtypes" 10 "stream.place/streamplace/pkg/streamplace" 11) 12 13// SendChatWebhook sends chat message to a specific webhook 14func SendChatWebhook(ctx context.Context, webhook *streamplace.ServerDefs_Webhook, authorDID string, scm *streamplace.ChatDefs_MessageView) error { 15 discordWebhook, err := webhookToDiscordWebhook(webhook) 16 if err != nil { 17 return fmt.Errorf("failed to convert webhook: %w", err) 18 } 19 20 return discord.SendChat(ctx, discordWebhook, authorDID, scm) 21} 22 23// SendLivestreamWebhook sends livestream notification to a specific webhook 24func SendLivestreamWebhook(ctx context.Context, webhook *streamplace.ServerDefs_Webhook, pdsURL string, lsv *streamplace.Livestream_LivestreamView, postView *bsky.FeedDefs_PostView, spcp *streamplace.ChatProfile) error { 25 discordWebhook, err := webhookToDiscordWebhook(webhook) 26 if err != nil { 27 return fmt.Errorf("failed to convert webhook: %w", err) 28 } 29 30 return discord.SendLivestream(ctx, discordWebhook, pdsURL, lsv, postView, spcp) 31} 32 33// webhookToDiscordWebhook converts streamplace.ServerDefs_Webhook to discordtypes.Webhook 34func webhookToDiscordWebhook(webhook *streamplace.ServerDefs_Webhook) (*discordtypes.Webhook, error) { 35 var rewriteRules []*discordtypes.WebhookRewrite 36 for _, rule := range webhook.Rewrite { 37 rewriteRules = append(rewriteRules, &discordtypes.WebhookRewrite{ 38 From: rule.From, 39 To: rule.To, 40 }) 41 } 42 43 var prefix, suffix string 44 if webhook.Prefix != nil { 45 prefix = *webhook.Prefix 46 } 47 if webhook.Suffix != nil { 48 suffix = *webhook.Suffix 49 } 50 51 return &discordtypes.Webhook{ 52 URL: webhook.Url, 53 Prefix: prefix, 54 Suffix: suffix, 55 Rewrite: rewriteRules, 56 }, nil 57}