Fixing build issues
This commit is contained in:
parent
c64ce68e85
commit
962c894f79
75
commands.go
75
commands.go
|
@ -176,45 +176,15 @@ func add(user *gumble.User, username, url string) {
|
|||
if urlService == nil {
|
||||
dj.SendPrivateMessage(user, INVALID_URL_MSG)
|
||||
} else {
|
||||
oldLength := dj.queue.Len()
|
||||
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()
|
||||
}
|
||||
if oldLength == 0 && dj.queue.Len() != 0 && !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)
|
||||
|
@ -223,35 +193,6 @@ func add(user *gumble.User, username, url string) {
|
|||
} 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()
|
||||
if newPlaylist, err := NewYouTubePlaylist(username, shortURL); err == nil {
|
||||
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 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 {
|
||||
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