Added Instagram support

This commit is contained in:
Logan G 2022-07-17 23:25:14 -06:00
parent 872c72c0de
commit 9b5b980e1d
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -136,6 +136,37 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
}
}
respond = true
} else if output, _ := regexp.MatchString("(http.*instagram\\.com/p/.*)|(http.*instagram\\.com/tv/.*)|(http.*instagram\\.com/reel/.*)", url); output {
log.Println("Instagram detected.")
response.Content = response.Content + fmt.Sprintf("<%s>", regexp.MustCompile("http.*instagram\\.com").ReplaceAllString(url, "https://bibliogram.art"))
result, err := goutubedl.New(context.Background(), url, goutubedl.Options{})
if err != nil {
log.Println(err)
continue
} else {
downloadResult, err := result.Download(context.Background(), result.Formats()[0].FormatID) // Insta only has one possible format to download :(
if err != nil {
log.Println(err)
continue
}
buf := new(bytes.Buffer)
buf.ReadFrom(downloadResult)
downloadResult.Close()
if buf.Len() <= 8*1024*1024 {
response.Files = append(response.Files, &discordgo.File {
Name: fmt.Sprintf("%s.%s", result.Info.ID, result.Formats()[0].Ext),
ContentType: "text/plain", // This is of course not true, but Discord doesn't give a shit
Reader: buf,
})
}
}
respond = true
}
}