Added Reddit
This commit is contained in:
parent
2cff5fa762
commit
18a07ec828
1 changed files with 43 additions and 0 deletions
|
@ -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