Fixing build issues
This commit is contained in:
parent
c64ce68e85
commit
962c894f79
69
commands.go
69
commands.go
|
@ -176,63 +176,8 @@ func add(user *gumble.User, username, url string) {
|
||||||
if urlService == nil {
|
if urlService == nil {
|
||||||
dj.SendPrivateMessage(user, INVALID_URL_MSG)
|
dj.SendPrivateMessage(user, INVALID_URL_MSG)
|
||||||
} else {
|
} else {
|
||||||
urlService.NewRequest(user, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
youtubePatterns := []string{
|
|
||||||
`https?:\/\/www\.youtube\.com\/watch\?v=([\w-]+)(\&t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/youtube\.com\/watch\?v=([\w-]+)(\&t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/youtu.be\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/youtube.com\/v\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/www.youtube.com\/v\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
|
||||||
}
|
|
||||||
matchFound := false
|
|
||||||
shortURL := ""
|
|
||||||
startOffset := ""
|
|
||||||
|
|
||||||
for _, pattern := range youtubePatterns {
|
|
||||||
if re, err := regexp.Compile(pattern); err == nil {
|
|
||||||
if re.MatchString(url) {
|
|
||||||
matchFound = true
|
|
||||||
matches := re.FindAllStringSubmatch(url, -1)
|
|
||||||
shortURL = matches[0][1]
|
|
||||||
if len(matches[0]) == 3 {
|
|
||||||
startOffset = matches[0][2]
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if matchFound {
|
|
||||||
if newSong, err := NewYouTubeSong(username, shortURL, startOffset, nil); err == nil {
|
|
||||||
dj.client.Self.Channel.Send(fmt.Sprintf(SONG_ADDED_HTML, username, newSong.title), false)
|
|
||||||
if dj.queue.Len() == 1 && !dj.audioStream.IsPlaying() {
|
|
||||||
if err := dj.queue.CurrentSong().Download(); err == nil {
|
|
||||||
dj.queue.CurrentSong().Play()
|
|
||||||
} else {
|
|
||||||
dj.SendPrivateMessage(user, AUDIO_FAIL_MSG)
|
|
||||||
dj.queue.CurrentSong().Delete()
|
|
||||||
dj.queue.OnSongFinished()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if fmt.Sprint(err) == "Song exceeds the maximum allowed duration." {
|
|
||||||
dj.SendPrivateMessage(user, VIDEO_TOO_LONG_MSG)
|
|
||||||
} else if fmt.Sprint(err) == "Invalid API key supplied." {
|
|
||||||
dj.SendPrivateMessage(user, INVALID_API_KEY)
|
|
||||||
} else {
|
|
||||||
dj.SendPrivateMessage(user, INVALID_YOUTUBE_ID_MSG)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Check to see if we have a playlist URL instead.
|
|
||||||
youtubePlaylistPattern := `https?:\/\/www\.youtube\.com\/playlist\?list=([\w-]+)`
|
|
||||||
if re, err := regexp.Compile(youtubePlaylistPattern); err == nil {
|
|
||||||
if re.MatchString(url) {
|
|
||||||
if dj.HasPermission(username, dj.conf.Permissions.AdminAddPlaylists) {
|
|
||||||
shortURL = re.FindStringSubmatch(url)[1]
|
|
||||||
oldLength := dj.queue.Len()
|
oldLength := dj.queue.Len()
|
||||||
if newPlaylist, err := NewYouTubePlaylist(username, shortURL); err == nil {
|
urlService.NewRequest(user, url)
|
||||||
dj.client.Self.Channel.Send(fmt.Sprintf(PLAYLIST_ADDED_HTML, username, newPlaylist.title), false)
|
|
||||||
if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() {
|
if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() {
|
||||||
if err := dj.queue.CurrentSong().Download(); err == nil {
|
if err := dj.queue.CurrentSong().Download(); err == nil {
|
||||||
dj.queue.CurrentSong().Play()
|
dj.queue.CurrentSong().Play()
|
||||||
|
@ -241,17 +186,13 @@ func add(user *gumble.User, username, url string) {
|
||||||
dj.queue.CurrentSong().Delete()
|
dj.queue.CurrentSong().Delete()
|
||||||
dj.queue.OnSongFinished()
|
dj.queue.OnSongFinished()
|
||||||
}
|
}
|
||||||
}
|
} else if fmt.Sprint(err) == "Song exceeds the maximum allowed duration." {
|
||||||
|
dj.SendPrivateMessage(user, VIDEO_TOO_LONG_MSG)
|
||||||
|
} else if fmt.Sprint(err) == "Invalid API key supplied." {
|
||||||
|
dj.SendPrivateMessage(user, INVALID_API_KEY)
|
||||||
} else {
|
} else {
|
||||||
dj.SendPrivateMessage(user, INVALID_YOUTUBE_ID_MSG)
|
dj.SendPrivateMessage(user, INVALID_YOUTUBE_ID_MSG)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
dj.SendPrivateMessage(user, NO_PLAYLIST_PERMISSION_MSG)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dj.SendPrivateMessage(user, INVALID_URL_MSG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue