Example #1
0
 public override async Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
 {
     if (!await TrackEnded(eventArgs))
     {
         Finished = true;
     }
 }
Example #2
0
        public override async Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
        {
            await base.OnTrackEndAsync(eventArgs);

            if (eventArgs.MayStartNext && !Queue.IsEmpty && !IsLooping)
            {
                await this.Channel.SendMessageAsync($"Now playing `{CurrentTrack.Title}` :play:");
            }
        }
        /// <summary>
        ///     Asynchronously triggered when a track ends.
        /// </summary>
        /// <param name="eventArgs">the track event arguments</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        public override async Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
        {
            if (eventArgs.MayStartNext)
            {
                await SkipAsync();
            }

            await base.OnTrackEndAsync(eventArgs);
        }
Example #4
0
        /// <summary>
        ///     Handles an event payload asynchronously.
        /// </summary>
        /// <param name="payload">the payload</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        protected virtual async Task OnEventReceived(EventPayload payload)
        {
            if (!Players.TryGetValue(payload.GuildId, out var player))
            {
                return;
            }

            // a track ended
            if (payload is TrackEndEvent trackEndEvent)
            {
                var args = new TrackEndEventArgs(player,
                                                 trackEndEvent.TrackIdentifier,
                                                 trackEndEvent.Reason);

                await Task.WhenAll(OnTrackEndAsync(args),
                                   player.OnTrackEndAsync(args));
            }

            // an exception occurred while playing a track
            if (payload is TrackExceptionEvent trackExceptionEvent)
            {
                var args = new TrackExceptionEventArgs(player,
                                                       trackExceptionEvent.TrackIdentifier,
                                                       trackExceptionEvent.Error);

                await Task.WhenAll(OnTrackExceptionAsync(args),
                                   player.OnTrackExceptionAsync(args));
            }

            // a track got stuck
            if (payload is TrackStuckEvent trackStuckEvent)
            {
                var args = new TrackStuckEventArgs(player,
                                                   trackStuckEvent.TrackIdentifier,
                                                   trackStuckEvent.Threshold);

                await Task.WhenAll(OnTrackStuckAsync(args),
                                   player.OnTrackStuckAsync(args));
            }

            // the voice web socket was closed
            if (payload is WebSocketClosedEvent webSocketClosedEvent)
            {
                await player.DisconnectAsync(PlayerDisconnectCause.WebSocketClosed);

                Players.Remove(payload.GuildId);
                player.Dispose();

                Logger?.Log(this, string.Format("Voice WebSocket was closed for player: {0}" +
                                                "\nClose Code: {1} ({2}, Reason: {3}, By Remote: {4}",
                                                payload.GuildId, webSocketClosedEvent.CloseCode,
                                                (int)webSocketClosedEvent.CloseCode, webSocketClosedEvent.Reason,
                                                webSocketClosedEvent.ByRemote ? "Yes" : "No"),
                            webSocketClosedEvent.ByRemote ? LogLevel.Warning : LogLevel.Debug);
            }
        }
Example #5
0
 private async Task <Task> OnTrackEnd(object sender, TrackEndEventArgs eventArgs)
 {
     if (eventArgs.Reason == TrackEndReason.Finished)
     {
         if (Tracks[eventArgs.Player.GuildId].Count > 0)
         {
             await eventArgs.Player.PlayAsync(Tracks[eventArgs.Player.GuildId].Dequeue());
         }
     }
     return(Task.CompletedTask);
 }
        /// <summary>
        ///     Asynchronously triggered when a track ends.
        /// </summary>
        /// <remarks>
        ///     When overriding this method without supering / base calling it, the disconnect on
        ///     stop function will be prevent.
        /// </remarks>
        /// <param name="eventArgs">the track event arguments</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        public virtual Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
        {
            if (DisconnectOnStop)
            {
                return(DisconnectAsync());
            }
            else
            {
                // The track ended, set to not playing
                State = PlayerState.NotPlaying;
            }

            return(Task.CompletedTask);
        }
 /// <summary>
 ///     Asynchronously triggered when a track ends.
 /// </summary>
 /// <param name="eventArgs">the track event arguments</param>
 /// <returns>a task that represents the asynchronous operation</returns>
 public override Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
 {
     // Note: It is intended that 'await base.OnTrackEndAsync(eventArgs);' is avoided here to
     // suppress the State update
     if (eventArgs.MayStartNext)
     {
         return(SkipAsync());
     }
     else if (_disconnectOnStop)
     {
         return(DisconnectAsync(PlayerDisconnectCause.Stop));
     }
     else
     {
         return(Task.CompletedTask);
     }
 }
        /// <summary>
        ///     Asynchronously triggered when a track ends.
        /// </summary>
        /// <param name="eventArgs">the track event arguments</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        public override async Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
        {
            if (eventArgs.Reason == TrackEndReason.LoadFailed)
            {
                botResponse = "Load failed for song. Retrying.";
                Queue.Insert(0, TrackDecoder.DecodeTrack(eventArgs.TrackIdentifier));
                await SkipAsync();

                return;
            }
            Console.WriteLine($"Track end ran. Args: {eventArgs.Reason}");
            if (eventArgs.Reason != TrackEndReason.Replaced && Queue.IsEmpty)
            {
                DisconnectOnStop = false;
                await base.OnTrackEndAsync(eventArgs);
            }
            if (eventArgs.MayStartNext)
            {
                await SkipAsync();
            }
        }
Example #9
0
 /// <summary>
 ///     Invokes the <see cref="TrackEnd"/> event asynchronously. (Can be override for event catching)
 /// </summary>
 /// <param name="eventArgs">the event arguments</param>
 /// <returns>a task that represents the asynchronous operation</returns>
 protected virtual Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
 => TrackEnd.InvokeAsync(this, eventArgs);
 internal Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
 => TrackEnd.InvokeAsync(this, eventArgs);
Example #11
0
 public static async Task TrackEnded(object sender, TrackEndEventArgs e)
 {
     var player = e.Player as QueuedLavalinkPlayer;
     await Task.CompletedTask;
 }
 /// <inheritdoc/>
 protected override Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
 => Task.WhenAll(base.OnTrackEndAsync(eventArgs), Cluster.OnTrackEndAsync(eventArgs));
 /// <summary>
 ///     Asynchronously triggered when a track ends.
 /// </summary>
 /// <param name="eventArgs">the track event arguments</param>
 /// <returns>a task that represents the asynchronous operation</returns>
 public override Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
 {
     ClearVotes();
     return(base.OnTrackEndAsync(eventArgs));
 }