Compare commits

...

2 commits

Author SHA1 Message Date
e89137224b Don't post if starting with @
All checks were successful
/ build (push) Successful in 1m40s
2025-11-03 10:17:18 +00:00
1d2347ab72 Add option to ignore old posts, default 24 hours 2025-11-03 10:08:22 +00:00

20
main.go
View file

@ -45,6 +45,7 @@ type handler struct {
var (
post = flag.String("post", "", "URL to a BlueSky 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")
)
func main() {
@ -189,12 +190,22 @@ func (h *handler) ProcessPost(event *models.Event) error {
ps, _ := h.bsky.ParsePost(event.Commit.Record)
po := ps.GetEmbeds()
cid, _ := strconv.ParseInt(os.Getenv("TG_CHANNEL_ID"), 10, 64)
isEditedPost := false
if ps.IsReply() { //|| ps.IsQuotePost() {
// don't want to post replies to channel
now := time.Now()
createdAt := ps.CreatedAt
duration := now.Sub(createdAt)
if duration.Hours() > *oldPosts ||
strings.HasPrefix(ps.Text, "@") ||
ps.IsReply() {
return nil
}
telegramRecord, telegramRecordErr := h.bsky.Bluesky.GetTelegramData(event.Commit.RKey)
if telegramRecordErr == "" {
isEditedPost = true
}
var captionText string
if ps.IsQuotePost() {
if ps.Embed.Record.Type == "app.bsky.embed.record" {
@ -282,6 +293,10 @@ func (h *handler) ProcessPost(event *models.Event) error {
}
if len(mediaGroup) == 0 {
log.Print("No mediaGroup to send, see previous error")
} else {
if isEditedPost {
resp, err := h.tg.Send(tgbotapi.NewEditMessageCaption(telegramRecord.ChannelID, telegramRecord.MessageID[0], captionText))
fmt.Println(resp, err)
} else {
resp, _ := h.tg.SendMediaGroup(tgbotapi.NewMediaGroup(cid, mediaGroup))
uri, cid := getLink(event)
@ -298,6 +313,7 @@ func (h *handler) ProcessPost(event *models.Event) error {
},
}, event.Commit.RKey)
}
}
} else {
m := tgbotapi.MessageConfig{}
if captionText == "" {