Compare commits
No commits in common. "e89137224bceb96b810e6904aa98cc0febd4b8a6" and "70b30a9313655b52e7e55de5a09b86b5fc049dcf" have entirely different histories.
e89137224b
...
70b30a9313
1 changed files with 17 additions and 33 deletions
50
main.go
50
main.go
|
|
@ -43,9 +43,8 @@ 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")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -190,22 +189,12 @@ func (h *handler) ProcessPost(event *models.Event) error {
|
||||||
ps, _ := h.bsky.ParsePost(event.Commit.Record)
|
ps, _ := h.bsky.ParsePost(event.Commit.Record)
|
||||||
po := ps.GetEmbeds()
|
po := ps.GetEmbeds()
|
||||||
cid, _ := strconv.ParseInt(os.Getenv("TG_CHANNEL_ID"), 10, 64)
|
cid, _ := strconv.ParseInt(os.Getenv("TG_CHANNEL_ID"), 10, 64)
|
||||||
isEditedPost := false
|
|
||||||
|
|
||||||
now := time.Now()
|
if ps.IsReply() { //|| ps.IsQuotePost() {
|
||||||
createdAt := ps.CreatedAt
|
// don't want to post replies to channel
|
||||||
duration := now.Sub(createdAt)
|
|
||||||
if duration.Hours() > *oldPosts ||
|
|
||||||
strings.HasPrefix(ps.Text, "@") ||
|
|
||||||
ps.IsReply() {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
telegramRecord, telegramRecordErr := h.bsky.Bluesky.GetTelegramData(event.Commit.RKey)
|
|
||||||
if telegramRecordErr == "" {
|
|
||||||
isEditedPost = true
|
|
||||||
}
|
|
||||||
|
|
||||||
var captionText string
|
var captionText string
|
||||||
if ps.IsQuotePost() {
|
if ps.IsQuotePost() {
|
||||||
if ps.Embed.Record.Type == "app.bsky.embed.record" {
|
if ps.Embed.Record.Type == "app.bsky.embed.record" {
|
||||||
|
|
@ -294,25 +283,20 @@ func (h *handler) ProcessPost(event *models.Event) error {
|
||||||
if len(mediaGroup) == 0 {
|
if len(mediaGroup) == 0 {
|
||||||
log.Print("No mediaGroup to send, see previous error")
|
log.Print("No mediaGroup to send, see previous error")
|
||||||
} else {
|
} else {
|
||||||
if isEditedPost {
|
resp, _ := h.tg.SendMediaGroup(tgbotapi.NewMediaGroup(cid, mediaGroup))
|
||||||
resp, err := h.tg.Send(tgbotapi.NewEditMessageCaption(telegramRecord.ChannelID, telegramRecord.MessageID[0], captionText))
|
uri, cid := getLink(event)
|
||||||
fmt.Println(resp, err)
|
var messageIDs []int
|
||||||
} else {
|
for _, msgID := range resp {
|
||||||
resp, _ := h.tg.SendMediaGroup(tgbotapi.NewMediaGroup(cid, mediaGroup))
|
messageIDs = append(messageIDs, msgID.MessageID)
|
||||||
uri, cid := getLink(event)
|
|
||||||
var messageIDs []int
|
|
||||||
for _, msgID := range resp {
|
|
||||||
messageIDs = append(messageIDs, msgID.MessageID)
|
|
||||||
}
|
|
||||||
h.bsky.Bluesky.CommitTelegramResponse(&bsky.TelegramRecord{
|
|
||||||
ChannelID: resp[0].Chat.ID,
|
|
||||||
MessageID: messageIDs,
|
|
||||||
Link: &bsky.Link{
|
|
||||||
Cid: cid,
|
|
||||||
URI: uri,
|
|
||||||
},
|
|
||||||
}, event.Commit.RKey)
|
|
||||||
}
|
}
|
||||||
|
h.bsky.Bluesky.CommitTelegramResponse(&bsky.TelegramRecord{
|
||||||
|
ChannelID: resp[0].Chat.ID,
|
||||||
|
MessageID: messageIDs,
|
||||||
|
Link: &bsky.Link{
|
||||||
|
Cid: cid,
|
||||||
|
URI: uri,
|
||||||
|
},
|
||||||
|
}, event.Commit.RKey)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m := tgbotapi.MessageConfig{}
|
m := tgbotapi.MessageConfig{}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue