Exemple #1
0
        private static async Task OnPlayReactionAsync(PaginatorSenderService sender, Paginator <object> paginator, Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel chan, SocketReaction reaction)
        {
            if (!(chan is IGuildChannel) || reaction.User.Value == null)
            {
                return;
            }
            IGuildUser guser = (IGuildUser)reaction.User.Value;

            if (guser.VoiceChannel == null)
            {
                return;
            }

            ITextChannel        textChan = (ITextChannel)chan;
            IMusicPlayerService music    = sender.ServiceManager.GetService <IMusicPlayerService>("Music");

            switch (paginator.CurrentValue)
            {
            case ILavaTrack track:
                await music.AddTrackAsync(guser.VoiceChannel, textChan, track);

                await chan.DeleteMessageAsync(paginator.Message);

                break;

            case string url:
                if (string.IsNullOrWhiteSpace(url))
                {
                    return;
                }

                SearchResult result = await music.LavaRestClient.SearchTracksAsync(url);

                List <ILavaTrack> tracks = result.Tracks.ToList();
                if (tracks.Count > 0)
                {
                    ILavaTrack tr = tracks[0];
                    await music.AddTrackAsync(guser.VoiceChannel, textChan, tr);

                    await chan.DeleteMessageAsync(paginator.Message);
                }
                else
                {
                    await sender.MessageSender.SendWarningAsync(chan, "music player", $"Could not add the following Url to the queue\n{url}");
                }

                break;
            }
        }
Exemple #2
0
        private async Task TryPlayUrlAsync(IMusicPlayerService music, ITextChannel textChan, IUserMessage msg, IGuildUser guser, string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return;                                 // can be null or empty apparently
            }
            IGuildUser botUser = await guser.Guild.GetCurrentUserAsync();

            await msg.RemoveReactionAsync(Emote, botUser);

            bool played = await this.TryPlaySpotifyAsync(music, textChan, guser, url);

            if (played)
            {
                return;
            }

            SearchResult result = await music.LavaRestClient.SearchTracksAsync(url);

            List <ILavaTrack> tracks = result.Tracks.ToList();

            switch (result.LoadType)
            {
            case LoadType.SearchResult:
            case LoadType.TrackLoaded:
                if (tracks.Count > 0)
                {
                    await music.AddTrackAsync(guser.VoiceChannel, textChan, tracks[0]);
                }
                break;

            case LoadType.PlaylistLoaded:
                if (tracks.Count > 0)
                {
                    await music.AddPlaylistAsync(guser.VoiceChannel, textChan, result.PlaylistInfo.Name, tracks);
                }
                break;

            case LoadType.LoadFailed:
                await this.SendNonPlayableContentAsync(guser, msg, textChan, url, "File is corrupted or does not have audio");

                this.Logger.Nice("music player", ConsoleColor.Yellow, $"Could add/play track from playable content ({url})");
                break;

            case LoadType.NoMatches:
                await this.SendNonPlayableContentAsync(guser, msg, textChan, url, "Could not find the track to be added/played");

                this.Logger.Nice("music player", ConsoleColor.Yellow, $"Could not find match for playable content ({url})");
                break;

            default:
                await this.SendNonPlayableContentAsync(guser, msg, textChan, url, "Unkown error");

                this.Logger.Nice("music player", ConsoleColor.Yellow, $"Unknown error ({url})");
                break;
            }
        }
Exemple #3
0
        private async Task <bool> TryPlaySpotifyAsync(IMusicPlayerService music, ITextChannel textChan, IGuildUser guser, string url)
        {
            SpotifyTrack track = await this.SpotifyToTrackAsync(url);

            if (track == null)
            {
                return(false);
            }

            await music.AddTrackAsync(guser.VoiceChannel, textChan, track);

            return(true);
        }