Added TikTok support

This commit is contained in:
Logan G 2022-07-20 18:03:34 -06:00
parent f5afb11f90
commit c5015145b2
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -184,6 +184,40 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
downloadResult.Close()
}
respond = true
} else if output, _ := regexp.MatchString("(http.*tiktok\\.com/\\@.*)", url); output {
log.Println("TikTok detected.")
response.Content = response.Content + fmt.Sprintf("\n<%s>", regexp.MustCompile("http.*tiktok\\.com").ReplaceAllString(url, "https://proxitok.pussthecat.org"))
result, err := goutubedl.New(context.Background(), url, goutubedl.Options{})
if err != nil {
log.Println(err)
continue
} else {
choice, err := getLargestFormat(result, 8*1024*1024)
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.Filesize/1024/1024)
if err == nil {
session.ChannelTyping(message.ChannelID)
downloadResult, err := result.Download(context.Background(), choice.FormatID)
if err != nil {
log.Println(err)
//session.ChannelMessageSend(message.ChannelID, err.Error())
continue
}
response.Files = append(response.Files, &discordgo.File {
Name: fmt.Sprintf("%s.%s", result.Info.ID, choice.Ext),
ContentType: "text/plain", // This is of course not true, but Discord doesn't give a shit
Reader: downloadResult,
})
defer downloadResult.Close()
} else {
log.Println(err)
}
}
respond = true
}
}