resolve own DID on posts
All checks were successful
/ build (push) Successful in 2m17s

This commit is contained in:
Astra 2025-11-06 16:17:07 +00:00
parent e89137224b
commit a3f4f4f54c

18
main.go
View file

@ -45,7 +45,7 @@ type handler struct {
var ( var (
post = flag.String("post", "", "URL to a BlueSky post") post = flag.String("post", "", "URL to a BlueSky post")
delete = flag.Bool("delete", false, "true/false to delete post") delete = flag.Bool("delete", false, "true/false to delete post")
oldPosts = flag.Float64("oldposttime", 24, "Ignore posts if createdAt more than this many hours ago") oldPosts = flag.Float64("oldposttime", 1, "Ignore posts if createdAt more than this many hours ago")
) )
func main() { func main() {
@ -208,6 +208,10 @@ func (h *handler) ProcessPost(event *models.Event) error {
var captionText string var captionText string
if ps.IsQuotePost() { if ps.IsQuotePost() {
ownHandle, handleErr := h.bsky.GetHandleFromDID(h.bsky.Bluesky.Cfg.DID)
if handleErr != nil {
ownHandle = h.bsky.Bluesky.Cfg.Handle
}
if ps.Embed.Record.Type == "app.bsky.embed.record" { if ps.Embed.Record.Type == "app.bsky.embed.record" {
handle, _ := h.bsky.GetHandleFromDID(strings.Split(ps.Embed.Record.Record.URI, "/")[2]) handle, _ := h.bsky.GetHandleFromDID(strings.Split(ps.Embed.Record.Record.URI, "/")[2])
captionText = fmt.Sprintf( captionText = fmt.Sprintf(
@ -218,7 +222,7 @@ func (h *handler) ProcessPost(event *models.Event) error {
handle, handle,
event.Did, event.Did,
event.Commit.RKey, event.Commit.RKey,
h.bsky.Bluesky.Cfg.Handle) ownHandle)
} else { } else {
handle, _ := h.bsky.GetHandleFromDID(strings.Split(ps.Embed.Record.URI, "/")[2]) handle, _ := h.bsky.GetHandleFromDID(strings.Split(ps.Embed.Record.URI, "/")[2])
captionText = fmt.Sprintf( captionText = fmt.Sprintf(
@ -229,15 +233,19 @@ func (h *handler) ProcessPost(event *models.Event) error {
handle, handle,
event.Did, event.Did,
event.Commit.RKey, event.Commit.RKey,
h.bsky.Bluesky.Cfg.Handle) ownHandle)
} }
} }
if captionText == "" { if captionText == "" {
ownHandle, handleErr := h.bsky.GetHandleFromDID(h.bsky.Bluesky.Cfg.DID)
if handleErr != nil {
ownHandle = h.bsky.Bluesky.Cfg.Handle
}
if ps.ProcessFacets(h.bsky.Bluesky.FetchAliases()) != "" { if ps.ProcessFacets(h.bsky.Bluesky.FetchAliases()) != "" {
captionText = fmt.Sprintf(postFormat, ps.ProcessFacets(h.bsky.Bluesky.FetchAliases()), h.bsky.Bluesky.Cfg.DID, event.Commit.RKey, h.bsky.Bluesky.Cfg.Handle) captionText = fmt.Sprintf(postFormat, ps.ProcessFacets(h.bsky.Bluesky.FetchAliases()), h.bsky.Bluesky.Cfg.DID, event.Commit.RKey, ownHandle)
} else { } else {
captionText = fmt.Sprintf("<a href=\"https://bsky.app/profile/%s/post/%s\">🦋 @%s</a>", h.bsky.Bluesky.Cfg.DID, event.Commit.RKey, h.bsky.Bluesky.Cfg.Handle) captionText = fmt.Sprintf("<a href=\"https://bsky.app/profile/%s/post/%s\">🦋 @%s</a>", h.bsky.Bluesky.Cfg.DID, event.Commit.RKey, ownHandle)
} }
} }