Add option to ignore old posts, default 24 hours
This commit is contained in:
parent
70b30a9313
commit
1d2347ab72
1 changed files with 35 additions and 15 deletions
20
main.go
20
main.go
|
|
@ -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,6 +190,20 @@ 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
|
||||
|
||||
now := time.Now()
|
||||
createdAt := ps.CreatedAt
|
||||
duration := now.Sub(createdAt)
|
||||
if duration.Hours() > *oldPosts {
|
||||
// don't post old posts
|
||||
return nil
|
||||
}
|
||||
|
||||
telegramRecord, telegramRecordErr := h.bsky.Bluesky.GetTelegramData(event.Commit.RKey)
|
||||
if telegramRecordErr == "" {
|
||||
isEditedPost = true
|
||||
}
|
||||
|
||||
if ps.IsReply() { //|| ps.IsQuotePost() {
|
||||
// don't want to post replies to channel
|
||||
|
|
@ -282,6 +297,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 +317,7 @@ func (h *handler) ProcessPost(event *models.Event) error {
|
|||
},
|
||||
}, event.Commit.RKey)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m := tgbotapi.MessageConfig{}
|
||||
if captionText == "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue