Compare commits
2 commits
c5015145b2
...
18a07ec828
Author | SHA1 | Date | |
---|---|---|---|
18a07ec828 | |||
2cff5fa762 |
1 changed files with 44 additions and 1 deletions
|
@ -26,7 +26,7 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
|
||||||
urls := rxStrict.FindAllString(message.Content, -1)
|
urls := rxStrict.FindAllString(message.Content, -1)
|
||||||
if len(urls) > 0 {
|
if len(urls) > 0 {
|
||||||
response := discordgo.MessageSend {
|
response := discordgo.MessageSend {
|
||||||
Content: "Woah there partner! I detect some services that aren't very privacy friendly. Let me help you with that!\n",
|
Content: "Woah there partner! I detect some services that aren't very privacy friendly. Let me help you with that!",
|
||||||
Reference: message.Reference(),
|
Reference: message.Reference(),
|
||||||
Files: []*discordgo.File{},
|
Files: []*discordgo.File{},
|
||||||
}
|
}
|
||||||
|
@ -218,6 +218,49 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
respond = true
|
||||||
|
} else if output, _ := regexp.MatchString("(http.*reddit\\.com/r/\\.*)", url); output {
|
||||||
|
log.Println("Reddit detected.")
|
||||||
|
|
||||||
|
response.Content = response.Content + fmt.Sprintf("\n<%s>", regexp.MustCompile("http.*reddit\\.com").ReplaceAllString(url, "https://libreddit.spike.codes"))
|
||||||
|
|
||||||
|
// Reddit's native format is 'mpegts', which Discord cannot preview. This code however does produce a usable video with audio.
|
||||||
|
/*
|
||||||
|
result, err := goutubedl.New(context.Background(), url, goutubedl.Options{})
|
||||||
|
if err != nil {
|
||||||
|
// If it's complaining due to a lack of videos, don't care.
|
||||||
|
if noVideo, _ := regexp.MatchString(".*No media found.*", err.Error()); noVideo {
|
||||||
|
respond = true
|
||||||
|
} else {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
videoChoice, audioChoice, err := getLargestDashFormat(result, 8*1024*1024)
|
||||||
|
log.Printf("Choice: %s+%s | Size: %fM\n", videoChoice.FormatID, audioChoice.FormatID, (videoChoice.FilesizeApprox+audioChoice.FilesizeApprox)/1024/1024)
|
||||||
|
if err == nil {
|
||||||
|
session.ChannelTyping(message.ChannelID)
|
||||||
|
downloadResult, err := result.Download(context.Background(), fmt.Sprintf("%s+%s", videoChoice.FormatID, audioChoice.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, videoChoice.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
|
respond = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue