diff --git a/mods/mastodon.go b/mods/mastodon.go
index 5f2b61f..a680150 100644
--- a/mods/mastodon.go
+++ b/mods/mastodon.go
@@ -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, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{
+ ReplyID: &update.MessageID,
+ })
+ return
+ }
+ broker.SendTextMessage(update.Chat, fmt.Sprintf("Fatto!", 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, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{
+ ReplyID: &update.MessageID,
+ })
+ return
+ }
+ broker.SendTextMessage(update.Chat, fmt.Sprintf("Fatto!", 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,