Compare commits
No commits in common. "25532e07f6229bd98c5214145a79e1e596769f77" and "d8cf1e36a59bff681c74b54ee0a93926dd6e3314" have entirely different histories.
25532e07f6
...
d8cf1e36a5
2 changed files with 16 additions and 18 deletions
33
main.go
33
main.go
|
@ -16,7 +16,6 @@ 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
|
||||
}
|
||||
|
||||
|
@ -41,7 +40,12 @@ func handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update) {
|
|||
searchMsg = msg.ReplyToMessage
|
||||
}
|
||||
|
||||
hasDownloadables := false
|
||||
if searchMsg.Entities == nil || len(searchMsg.Entities) < 1 {
|
||||
if explicit {
|
||||
bot.Send(respondWith(msg, "Ese mensaje no tiene ningún link!"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < len(searchMsg.Entities); i++ {
|
||||
e := searchMsg.Entities[i]
|
||||
|
@ -55,41 +59,36 @@ func handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update) {
|
|||
if explicit {
|
||||
bot.Send(respondWithMany(msg, "No se pudo detectar la URL ", urlString, "."))
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
if url.Hostname() != "vm.tiktok.com" {
|
||||
if explicit {
|
||||
bot.Send(respondWithMany(msg, "La URL ", urlString, " no es de TikTok."))
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
hasDownloadables = true
|
||||
|
||||
log.Printf("Downloading %s", urlString)
|
||||
lookup, err := Lookup(urlString)
|
||||
if err != nil {
|
||||
bot.Send(respondWithMany(msg, "Hubo un error al descargar ", urlString, "."))
|
||||
continue
|
||||
return
|
||||
}
|
||||
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() {
|
||||
|
|
|
@ -18,7 +18,6 @@ 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"`
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue