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.ReplyToMessageID = msg.MessageID
res.DisableWebPagePreview = true
res.ParseMode = "markdown"
return res
}
@ -40,12 +41,7 @@ func handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update) {
searchMsg = msg.ReplyToMessage
}
if searchMsg.Entities == nil || len(searchMsg.Entities) < 1 {
if explicit {
bot.Send(respondWith(msg, "Ese mensaje no tiene ningún link!"))
}
return
}
hasDownloadables := false
for i := 0; i < len(searchMsg.Entities); i++ {
e := searchMsg.Entities[i]
@ -59,36 +55,41 @@ func handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update) {
if explicit {
bot.Send(respondWithMany(msg, "No se pudo detectar la URL ", urlString, "."))
}
return
continue
}
if url.Hostname() != "vm.tiktok.com" {
if explicit {
bot.Send(respondWithMany(msg, "La URL ", urlString, " no es de TikTok."))
}
return
continue
}
hasDownloadables = true
log.Printf("Downloading %s", urlString)
lookup, err := Lookup(urlString)
if err != nil {
bot.Send(respondWithMany(msg, "Hubo un error al descargar ", urlString, "."))
return
continue
}
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.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)
}
if !hasDownloadables && explicit {
bot.Send(respondWithMany(msg, "No encontré URLs descargables en ese mensaje."))
}
}
func main() {

View file

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