Example #1
0
        private async Task TrackFinish(TrackEndedEventArgs arg)
        {
            var player    = arg.Player;
            var endReason = arg.Reason;
            var ptrack    = arg.Track;

            var guild = GetOrAddConfig(player.VoiceChannel.GuildId);

            if (guild.Repeat)                                 // If the guild enabled repeating, do this
            {
                if (guild.IsPlayed)                           // If the previous playing track was replaced, do this
                {
                    if (endReason != TrackEndReason.Replaced) // If the track wasn't replaced, do this
                    {
                        guild.IsPlayed = false;
                        var track = guild.Queue.Dequeue();
                        await player.TextChannel.SendMessageAsync("", false, await EmbedMethods.GetEmbedQueue(track, guild.Queue, ptrack));

                        await player.PlayAsync(track);
                    }
                    else                     // If it wasn't replaced, don't do anything because it doesn't need to be added at the end of the queue.
                    {
                        return;
                    }
                }
                else
                {
                    if (endReason == TrackEndReason.Replaced)                     // If the track was replaced, declare that it was replaced
                    {
                        guild.IsPlayed = true;
                        guild.Queue.Enqueue(new TrackInput(ptrack, guild.CurrentUserPlaying));
                    }
                    else
                    {
                        guild.Queue.Enqueue(new TrackInput(ptrack, guild.CurrentUserPlaying));
                        var track = guild.Queue.Dequeue();
                        await player.TextChannel.SendMessageAsync("", false, await EmbedMethods.GetEmbedQueue(track, guild.Queue, ptrack));

                        await player.PlayAsync(track);
                    }
                }
            }
            else             // If the guild didn't enable repeating do this
            {
                if (endReason != TrackEndReason.Replaced)
                {
                    if (guild.Queue.Count > 0)
                    {
                        var track = guild.Queue.Dequeue();
                        guild.DecrementUser(guild.CurrentUserPlaying);
                        await player.TextChannel.SendMessageAsync("", false, await EmbedMethods.GetEmbedQueue(track, guild.Queue, ptrack));

                        guild.CurrentUserPlaying = track.UserInputter;
                        await player.PlayAsync(track);
                    }
                }
            }
        }
Example #2
0
        public async Task TrackFinished(LavaPlayer player, LavaTrack ptrack, TrackEndReason endReason)
        {
            var guild = GetOrAddConfig(player.VoiceChannel.GuildId);

            if (guild.Repeat)
            {
                if (guild.IsPlayed)
                {
                    if (endReason != TrackEndReason.Replaced)
                    {
                        guild.IsPlayed = false;
                        var track = guild.Queue.Dequeue();
                        await player.TextChannel.SendMessageAsync("", false, await EmbedMethods.GetEmbedQueue(track, guild.Queue, ptrack));

                        await player.PlayAsync(track);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (endReason == TrackEndReason.Replaced)
                    {
                        guild.IsPlayed = true;
                        guild.Queue.Enqueue(ptrack);
                    }
                    else
                    {
                        guild.Queue.Enqueue(ptrack);
                        var track = guild.Queue.Dequeue();
                        await player.TextChannel.SendMessageAsync("", false, await EmbedMethods.GetEmbedQueue(track, guild.Queue, ptrack));

                        await player.PlayAsync(track);
                    }
                }
            }
            else
            {
                if (endReason != TrackEndReason.Replaced)
                {
                    if (guild.Queue.Count > 0)
                    {
                        var track = guild.Queue.Dequeue();
                        await player.TextChannel.SendMessageAsync("", false, await EmbedMethods.GetEmbedQueue(track, guild.Queue, ptrack));

                        await player.PlayAsync(track);
                    }
                }
            }
        }