Made max file size a const

This commit is contained in:
Logan G 2023-05-05 16:50:05 -06:00
parent ec5f265793
commit 294e68db7d
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -13,6 +13,8 @@ import (
"mvdan.cc/xurls/v2" // Peak lazy
)
const MaxSize = 25*1024*1024
// This function will be called every time a new message is created on any channel that the authenticated bot has access to.
func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself
@ -63,7 +65,7 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
continue
} else {
choice, err := getLargestFormat(result, 25*1024*1024)
choice, err := getLargestFormat(result, MaxSize)
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.FilesizeApprox/1024/1024)
if err == nil {
session.ChannelTyping(message.ChannelID)
@ -109,12 +111,12 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
continue
} else if result.Info.AgeLimit < 18 && ! result.Info.IsLive {
/*
videoChoice, audioChoice, err := getLargestDashFormat(result, 25*1024*1024)
videoChoice, audioChoice, err := getLargestDashFormat(result, MaxSize)
log.Printf("Choice: %s+%s | Size: %fM\n", videoChoice.FormatID, audioChoice.FormatID, (videoChoice.Filesize+audioChoice.Filesize)/1024/1024)
if err == nil {
downloadResult, err := result.Download(context.Background(), fmt.Sprintf("%s+%s", videoChoice.FormatID, audioChoice.FormatID))
*/
choice, err := getLargestYTFormat(result, 25*1024*1024)
choice, err := getLargestYTFormat(result, MaxSize)
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.FilesizeApprox/1024/1024)
if err == nil {
session.ChannelTyping(message.ChannelID)
@ -159,11 +161,11 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
// Test to see if the result is more than 8MB through the tried and true method of downloading it into a 8MB slice and seeing if it errors out
var buf = make([]byte, 25*1024*1024 + 1)
var buf = make([]byte, MaxSize + 1)
size, err := io.ReadFull(downloadResult, buf)
// This section is probably really bad, don't copy it. Actually, don't even look at it.
if size <= 25*1024*1024 && err.Error() == "unexpected EOF" {
if size <= MaxSize && err.Error() == "unexpected EOF" {
log.Printf("Video Size: %fM", float64(size)/1024/1024)
var newBuf = make([]byte, size)
@ -195,7 +197,7 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
log.Println(err)
continue
} else {
choice, err := getLargestFormat(result, 25*1024*1024)
choice, err := getLargestFormat(result, MaxSize)
log.Printf("Choice: %s | Size: %fM\n", choice.FormatID, choice.Filesize/1024/1024)
if err == nil {
session.ChannelTyping(message.ChannelID)
@ -237,7 +239,7 @@ func messageCreate(session *discordgo.Session, message *discordgo.MessageCreate)
continue
} else {
videoChoice, audioChoice, err := getLargestDashFormat(result, 25*1024*1024)
videoChoice, audioChoice, err := getLargestDashFormat(result, MaxSize)
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)