7 Commits

Author SHA1 Message Date
williamp 509dab5395 Merge pull request 'automate management of loading emote' (#49) from automatic-loading-emote into master
Build and Push Docker Image / build-and-push (push) Successful in 40s
Build and Push Docker Image / deploy-on-green (push) Successful in 6s
Reviewed-on: #49
2026-03-10 01:00:31 +00:00
williamp 6b9934a221 automate management of loading emote
Build only (for PRs) / build-only (pull_request) Successful in 4m52s
2026-03-09 14:25:56 -04:00
williamp adefe2f177 Merge pull request 'optimize codebase' (#48) from code-cleanup into master
Build and Push Docker Image / build-and-push (push) Successful in 14s
Build and Push Docker Image / deploy-on-green (push) Successful in 6s
Reviewed-on: #48
2026-03-09 16:14:21 +00:00
williamp 084b7ed979 optimize codebase
Build only (for PRs) / build-only (pull_request) Successful in 4m43s
main.go:
- Eliminated ~160 lines of duplicate code: Extracted 3 new helper functions at the bottom of the file:
buildVideoMenuOptions([]VideoOption) — builds the Discord select menu options for video formats
buildAudioMenuOptions([]AudioOption) — same for audio
fetchAndShowFormats(s, i, url) — fetches formats, sorts them, builds menus, stores state, and edits the interaction; previously duplicated identically in both the download and download video command handlers
- Fixed time.Sleep ordering bug: The startAsyncDownload goroutine was launched before InteractionRespond with a 100ms sleep to compensate. Now the download is launched after InteractionRespond returns — no sleep needed. Removed "time" import.
- Used helpers in video_select handler: The two inline menu-building loops in that handler now call buildAudioMenuOptions / buildVideoMenuOptions

misc.go:
- Moved regexp.MustCompile(...) to a package-level var urlPattern — previously it recompiled the regex on every call to extractURLFromString
- Simplified the function body to a single return line
2026-03-09 11:10:33 -04:00
williamp 51e1cc5e85 Merge pull request 'chore(deps): update module github.com/lrstanley/go-ytdlp to v1.3.3' (#47) from renovate/github.com-lrstanley-go-ytdlp-1.x into master
Build and Push Docker Image / build-and-push (push) Successful in 5m31s
Build and Push Docker Image / deploy-on-green (push) Successful in 8s
Reviewed-on: #47
2026-03-08 15:55:17 +00:00
williamp d3e6ddebcd remove my fork after my changes were merged upstream
Build only (for PRs) / build-only (pull_request) Successful in 4m27s
2026-03-08 11:50:09 -04:00
renovate-bot 558f95ad9d chore(deps): update module github.com/lrstanley/go-ytdlp to v1.3.3
Build only (for PRs) / build-only (pull_request) Successful in 6m37s
2026-03-08 07:01:17 +00:00
5 changed files with 43 additions and 7 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

+1 -5
View File
@@ -2,13 +2,9 @@ module git.dubyatp.xyz/williamp/yt-dlp-bot
go 1.25.2
//replace github.com/lrstanley/go-ytdlp => /home/williamp/go-ytdlp
replace github.com/lrstanley/go-ytdlp => github.com/dubyatp/go-ytdlp v0.0.0-20260308044557-db32b29c1590
require (
github.com/bwmarrin/discordgo v0.29.0
github.com/lrstanley/go-ytdlp v1.3.2
github.com/lrstanley/go-ytdlp v1.3.3
)
require (
+2
View File
@@ -14,6 +14,8 @@ github.com/dubyatp/go-ytdlp v0.0.0-20260308044557-db32b29c1590 h1:27d1UwjlfuF/kw
github.com/dubyatp/go-ytdlp v0.0.0-20260308044557-db32b29c1590/go.mod h1:VgjnTrvkTf+23JuySjyPq1iQ8ijSovBtTPpXH5XrLtI=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/lrstanley/go-ytdlp v1.3.3 h1:Y9kJcdTwskPWDiwONMIl501Dhi+OrTF7HHY6J6+Lbco=
github.com/lrstanley/go-ytdlp v1.3.3/go.mod h1:VgjnTrvkTf+23JuySjyPq1iQ8ijSovBtTPpXH5XrLtI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
+4
View File
@@ -371,6 +371,10 @@ func main() {
}
})
log.Println("Initialize loading emoji")
initLoadingEmoji(s)
log.Println("Adding commands")
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
for i, v := range commands {
+36 -2
View File
@@ -2,11 +2,45 @@ package main
import (
"fmt"
"os"
"log"
"regexp"
_ "embed"
"encoding/base64"
"github.com/bwmarrin/discordgo"
)
var loading_emoji = os.Getenv("LOADING_EMOJI")
var loading_emoji string
//go:embed assets/loading.webp
var rawLoadingEmoji []byte
var loadingEmojiBase64 = func() string {
s := "data:image/webp;base64," + base64.StdEncoding.EncodeToString(rawLoadingEmoji)
rawLoadingEmoji = nil
return s
}()
func initLoadingEmoji(s *discordgo.Session) {
emojis, err := s.ApplicationEmojis(s.State.User.ID)
if err != nil {
log.Panic("Cannot get emojis")
}
for _, e := range emojis {
if e.Name == "loading" {
loading_emoji = fmt.Sprintf("<a:%s:%s>", e.Name, e.ID)
return
}
}
e, err := s.ApplicationEmojiCreate(s.State.User.ID, &discordgo.EmojiParams{
Name: "loading",
Image: loadingEmojiBase64,
})
if err != nil {
log.Panicf("Cannot create loading emoji: %s", err)
}
loading_emoji = fmt.Sprintf("<a:%s:%s>", e.Name, e.ID)
}
var urlPattern = regexp.MustCompile(`https?://\S+`)