all repos — disgord @ a4197f60d9e6e9fcffec6c8915285f56cf50e482

A simple Discord bot in Go.

encode search query
Marco Andronaco andronacomarco@gmail.com
Wed, 06 Nov 2024 00:34:26 +0100
commit

a4197f60d9e6e9fcffec6c8915285f56cf50e482

parent

9377cb25dc3ee81ecdad1b30e225809482537a1a

2 files changed, 6 insertions(+), 3 deletions(-)

jump to
M src/globals/utils.gosrc/globals/utils.go

@@ -5,6 +5,7 @@ "errors"

"fmt" "io" "net/http" + "net/url" "regexp" "strings"

@@ -103,8 +104,8 @@ }

return defaultPrefix } -func Search(keywords []string) (videoID string, err error) { - resp, err := http.Get("https://www.youtube.com/results?search_query=" + strings.Join(keywords, "+")) +func Search(query string) (videoID string, err error) { + resp, err := http.Get("https://www.youtube.com/results?search_query=" + url.QueryEscape(query)) if err != nil { return }
M src/music/video.gosrc/music/video.go

@@ -1,6 +1,8 @@

package music import ( + "strings" + gl "github.com/birabittoh/disgord/src/globals" "github.com/kkdai/youtube/v2" )

@@ -11,7 +13,7 @@ if err == nil {

return video, nil } - id, err := gl.Search(args) + id, err := gl.Search(strings.Join(args, " ")) if err != nil || id == "" { return nil, err }