optimize codebase #48

Merged
williamp merged 1 commits from code-cleanup into master 2026-03-09 16:14:22 +00:00
Owner

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
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
williamp added 1 commit 2026-03-09 14:48:02 +00:00
optimize codebase
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 3m33s
a44bb1bf34
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
williamp added 1 commit 2026-03-09 14:59:53 +00:00
bugfix: handle lack of separate audio/video streams
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 3m47s
52337254b6
williamp added 1 commit 2026-03-09 15:05:24 +00:00
Merge branch 'master' into code-cleanup
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 4m52s
ff02993a0a
williamp force-pushed code-cleanup from ff02993a0a to 084b7ed979 2026-03-09 15:11:11 +00:00 Compare
williamp merged commit adefe2f177 into master 2026-03-09 16:14:22 +00:00
williamp deleted branch code-cleanup 2026-03-09 16:14:22 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: williamp/yt-dlp-bot#48