1
0
Fork 0

Handle only text and photo
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Daniele Tricoli 2022-03-04 02:29:17 +01:00
parent 5caf9c4618
commit 4c082f2e03

View file

@ -2,6 +2,7 @@ package cmd
import ( import (
"context" "context"
"fmt"
"log" "log"
"os" "os"
"sort" "sort"
@ -51,19 +52,37 @@ the specified Mastodon account.`,
for update := range updates { for update := range updates {
if update.Message != nil { if update.Message != nil {
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
log.Println(update.Message)
status, err := c.PostStatus(context.Background(), &mastodon.Toot{ if update.Message.Text != "" {
Status: update.Message.Text, log.Println("Text message received.")
Visibility: parseMastodonVisibility(os.Getenv(MASTODON_TOOT_VISIBILITY)), status, err := c.PostStatus(context.Background(), &mastodon.Toot{
}) Status: update.Message.Text,
Visibility: parseMastodonVisibility(os.Getenv(MASTODON_TOOT_VISIBILITY)),
})
if err != nil {
log.Fatalf("Could not post status: %v", err)
}
log.Printf("Posted status %s", status.URL)
} else if update.Message.Photo != nil {
log.Println("Photo received.")
// Telegram provides multiple sizes of photo, just take the
// biggest.
biggest_photo := tgbotapi.PhotoSize{FileSize: 0}
for _, photo := range update.Message.Photo {
if photo.FileSize > biggest_photo.FileSize {
biggest_photo = photo
}
}
url, _ := bot.GetFileDirectURL(biggest_photo.FileID)
fmt.Println(url)
if err != nil {
log.Fatalf("Could not post status: %v", err)
} }
// fmt.Printf("%#v\n\n", update.Message)
log.Printf("Posted status %s", status.URL)
} }
} }
}, },