Add message
This commit is contained in:
parent
758fa5c640
commit
188b1caa04
1 changed files with 25 additions and 4 deletions
|
@ -66,6 +66,7 @@ func mastodon_message(broker *tg.Broker, update tg.APIMessage) {
|
|||
// Make replies work
|
||||
if update.ReplyTo != nil {
|
||||
update.User = update.ReplyTo.User
|
||||
update.Text = update.ReplyTo.Text
|
||||
if update.Text != nil && update.ReplyTo.Photo != nil {
|
||||
update.Photo = update.ReplyTo.Photo
|
||||
update.Caption = update.Text
|
||||
|
@ -111,21 +112,41 @@ func mastodon_message(broker *tg.Broker, update tg.APIMessage) {
|
|||
return
|
||||
}
|
||||
|
||||
sendToot(strings.TrimSpace(fmt.Sprintf("%s\n(da %s)", *(update.Caption), update.User.FirstName)), attach.ID)
|
||||
status, err := sendToot(strings.TrimSpace(fmt.Sprintf("%s\n(da %s)", *(update.Caption), update.User.FirstName)), attach.ID)
|
||||
if err != nil {
|
||||
log.Printf("[mastodon] Send toot failed: %s\n", err.Error())
|
||||
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @hamcha controlla la console!", &tg.MessageOptions{
|
||||
ReplyID: &update.MessageID,
|
||||
})
|
||||
return
|
||||
}
|
||||
broker.SendTextMessage(update.Chat, fmt.Sprintf("<a href=\"%s\">Fatto!</a>", status.URL), &tg.MessageOptions{
|
||||
ReplyID: &update.MessageID,
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
sendToot(fmt.Sprintf("%s\n(da %s)", *(update.Text), update.User.FirstName), "")
|
||||
status, err := sendToot(fmt.Sprintf("%s\n(da %s)", *(update.Text), update.User.FirstName), "")
|
||||
if err != nil {
|
||||
log.Printf("[mastodon] Send toot failed: %s\n", err.Error())
|
||||
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @hamcha controlla la console!", &tg.MessageOptions{
|
||||
ReplyID: &update.MessageID,
|
||||
})
|
||||
return
|
||||
}
|
||||
broker.SendTextMessage(update.Chat, fmt.Sprintf("<a href=\"%s\">Fatto!</a>", status.URL), &tg.MessageOptions{
|
||||
ReplyID: &update.MessageID,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func sendToot(status string, media mastodon.ID) {
|
||||
func sendToot(status string, media mastodon.ID) (*mastodon.Status, error) {
|
||||
var medialist []mastodon.ID
|
||||
if media != "" {
|
||||
medialist = []mastodon.ID{media}
|
||||
}
|
||||
mastodonClient.PostStatus(context.Background(), &mastodon.Toot{
|
||||
return mastodonClient.PostStatus(context.Background(), &mastodon.Toot{
|
||||
Status: status,
|
||||
MediaIDs: medialist,
|
||||
Sensitive: false,
|
||||
|
|
Reference in a new issue