4 Commits

Author SHA1 Message Date
509dab5395 Merge pull request 'automate management of loading emote' (#49) from automatic-loading-emote into master
All checks were successful
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
6b9934a221 automate management of loading emote
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 4m52s
2026-03-09 14:25:56 -04:00
adefe2f177 Merge pull request 'optimize codebase' (#48) from code-cleanup into master
All checks were successful
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
084b7ed979 optimize codebase
All checks were successful
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
3 changed files with 40 additions and 2 deletions

BIN
app/assets/loading.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

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 {

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+`)