Compare commits

...

4 commits

2 changed files with 18 additions and 16 deletions

33
main.go
View file

@ -16,6 +16,7 @@ func respondWith(msg *tgbotapi.Message, str string) tgbotapi.MessageConfig {
res := tgbotapi.NewMessage(msg.Chat.ID, str) res := tgbotapi.NewMessage(msg.Chat.ID, str)
res.ReplyToMessageID = msg.MessageID res.ReplyToMessageID = msg.MessageID
res.DisableWebPagePreview = true res.DisableWebPagePreview = true
res.ParseMode = "markdown"
return res return res
} }
@ -40,12 +41,7 @@ func handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update) {
searchMsg = msg.ReplyToMessage searchMsg = msg.ReplyToMessage
} }
if searchMsg.Entities == nil || len(searchMsg.Entities) < 1 { hasDownloadables := false
if explicit {
bot.Send(respondWith(msg, "Ese mensaje no tiene ningún link!"))
}
return
}
for i := 0; i < len(searchMsg.Entities); i++ { for i := 0; i < len(searchMsg.Entities); i++ {
e := searchMsg.Entities[i] e := searchMsg.Entities[i]
@ -59,36 +55,41 @@ func handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update) {
if explicit { if explicit {
bot.Send(respondWithMany(msg, "No se pudo detectar la URL ", urlString, ".")) bot.Send(respondWithMany(msg, "No se pudo detectar la URL ", urlString, "."))
} }
return continue
} }
if url.Hostname() != "vm.tiktok.com" { if url.Hostname() != "vm.tiktok.com" {
if explicit { if explicit {
bot.Send(respondWithMany(msg, "La URL ", urlString, " no es de TikTok.")) bot.Send(respondWithMany(msg, "La URL ", urlString, " no es de TikTok."))
} }
return continue
} }
hasDownloadables = true
log.Printf("Downloading %s", urlString) log.Printf("Downloading %s", urlString)
lookup, err := Lookup(urlString) lookup, err := Lookup(urlString)
if err != nil { if err != nil {
bot.Send(respondWithMany(msg, "Hubo un error al descargar ", urlString, ".")) bot.Send(respondWithMany(msg, "Hubo un error al descargar ", urlString, "."))
return continue
} }
log.Println(lookup) log.Println(lookup)
if !lookup.Success {
if len(lookup.Message) > 0 {
bot.Send(respondWithMany(msg, "Hubo un error al descargar ", urlString, ": `", lookup.Message, "`"))
} else {
bot.Send(respondWithMany(msg, "Hubo un error al descargar ", urlString, "."))
}
continue
}
res := tgbotapi.NewVideo(msg.Chat.ID, *lookup) res := tgbotapi.NewVideo(msg.Chat.ID, *lookup)
res.ReplyToMessageID = msg.MessageID res.ReplyToMessageID = msg.MessageID
// if info, err := readInfoFile(&infoPath); err != nil {
// res.Caption = "Hubo un error consiguiendo el titulo de este video."
// log.Println("error reading info file", err)
// } else {
// res.Caption = info.Title
// }
bot.Send(res) bot.Send(res)
} }
if !hasDownloadables && explicit {
bot.Send(respondWithMany(msg, "No encontré URLs descargables en ese mensaje."))
}
} }
func main() { func main() {

View file

@ -18,6 +18,7 @@ type LookupResponse struct {
LikeCount int `json:"like_count"` LikeCount int `json:"like_count"`
ShareCount int `json:"share_count"` ShareCount int `json:"share_count"`
Success bool `json:"success"` Success bool `json:"success"`
Message string `json:"message"`
Token string `json:"token"` Token string `json:"token"`
} }