Add message

This commit is contained in:
Hamcha 2019-05-23 14:31:28 +02:00
parent 758fa5c640
commit 188b1caa04
Signed by: hamcha
GPG key ID: A40413D21021EAEE

View file

@ -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,