private async Task PlaybackFinished(LavalinkGuildConnection guildConnection, TrackFinishEventArgs e) { var trackFind = this.Playlist.FirstOrDefault(t => string.Equals(t.Key?.Title, e.Track.Title)); if (!(trackFind.Key is null && trackFind.Value is null)) { this.Playlist.Remove(trackFind.Key); } if (this.Playlist.Any()) { await this.LavalinkGuildConnection.PlayAsync(this.Playlist.Keys.FirstOrDefault()); } else { await trackFind.Value.RespondAsync("There are no more songs in the playlist, disconnecting me from the voice channel."); await this.LavalinkGuildConnection.DisconnectAsync(false); if (this._isPlaying) { this._isPlaying = false; } if (!this._isPaused) { this._isPaused = true; } if (!this._isStopped) { this._isStopped = true; } } }
private async Task Player_PlaybackFinished(LavalinkGuildConnection con, TrackFinishEventArgs e) { await Task.Delay(500); this.IsPlaying = false; await this.PlayHandlerAsync(); }
/// <summary> /// Event handler when the player is finished playing a track /// </summary> /// <param name="e"></param> /// <returns></returns> private async Task Playback_Done(TrackFinishEventArgs e) { await Task.Delay(500).ConfigureAwait(false); this.IsPlaying = false; await this.PlayHandler(); }
private async Task PlaybackFinished(TrackFinishEventArgs e) { await Task.Delay(600).ConfigureAwait(false); if (this.LavalinkConnection != null) { if (this.IsMessageLast()) { await this.PlayingMessage.ModifyAsync(embed : await this.NowPlayingEmbedAsync()).ConfigureAwait(false); } else { var chn = this.PlayingMessage.Channel; await this.PlayingMessage.DeleteAsync(); this.PlayingMessage = await chn.SendMessageAsync(embed : await this.NowPlayingEmbedAsync()).ConfigureAwait(false); } var musicSource = this.MusicSources.First(x => x.IsPresent()); var trackUri = await musicSource.GetCurrentSong(); var trackLoad = await this.Lavalink.LavalinkNode.GetTracksAsync(trackUri); this.InternalPlay(trackLoad.Tracks.First()); } }
private async Task PlaybackFinished(TrackFinishEventArgs e) { await Task.Delay(500); this.IsPlaying = false; await this.PlayHandlerAsync(); }
private async Task PlayNext(LavalinkGuildConnection conn, TrackFinishEventArgs args) { if (conn.CurrentState.CurrentTrack != null) { if (PrevQueueCount == 0) { conn.PlaybackFinished += PlayNext; } return; } var track = Queue.Dequeue(); await conn.PlayAsync(track); if (Queue.Count > 0) { conn.PlaybackFinished += PlayNext; } var builder = new DiscordEmbedBuilder() .WithTitle("Playing now:") .WithDescription($"[{track.Title}]({track.Uri.AbsoluteUri})"); var message = await SoundContext.RespondAsync(null, false, builder.Build()); }
internal Task InternalPlaybackFinishedAsync(TrackFinishData e) { this.CurrentState.CurrentTrack = default; var ea = new TrackFinishEventArgs(this, LavalinkUtilities.DecodeTrack(e.Track), e.Reason); return(this._playbackFinished.InvokeAsync(ea)); }
private async Task LavalinkVoice_PlaybackFinished(TrackFinishEventArgs e, DiscordChannel responseChannel) { if (responseChannel == null) { return; } await responseChannel.SendMessageAsync($"Playback of {Formatter.Bold(Formatter.Sanitize(e.Track.Title))} by {Formatter.Bold(Formatter.Sanitize(e.Track.Author))} finished.").ConfigureAwait(false); }
async Task PlaybackFinished(LavalinkGuildConnection conn, TrackFinishEventArgs e) { if (e.Reason != TrackEndReason.Finished) { return; } var MusicData = this.musicData.First(xr => xr.GuildId == conn.Guild.Id); if (MusicData.Queue.Count == 0) { await this.Leave(e.Player.Guild); } await this.Play(e.Player.Guild); }
private async Task PlayTrack(TrackFinishEventArgs e) { if (e.Reason == TrackEndReason.Replaced) { return; } if (e.Player.Channel.Users.Count() == 1) { _Playlist.Clear(); await _Cmdctx.RespondAsync("Good bye :person_bowing:"); _LavalinkGuild.Disconnect(); await _LavalinkNode.StopAsync(); return; } if (_Playlist.Count > 1) { _Playlist.Dequeue(); _LavalinkGuild.Play(_Playlist.Peek()); await _Cmdctx.RespondAsync($"**[Playing]** {_Playlist.Peek().Title}"); } else if (_Playlist.Count == 1) { _Playlist.Clear(); await Task.Delay(2000); await _Cmdctx.RespondAsync("Queue concluded."); await Task.Delay(30000); _LavalinkGuild.Disconnect(); await _LavalinkNode.StopAsync(); } }
public static async Task LavalinkTrackFinish(LavalinkGuildConnection lava, TrackFinishEventArgs e) { try { var g = Bot.Guilds[e.Player.Guild.Id]; var lastPlayedSongs = await Database.GetLPL(e.Player.Guild); switch (e.Reason) { case TrackEndReason.Stopped: { g.musicInstance.playstate = Playstate.Stopped; g.musicInstance.guildConnection.PlaybackFinished -= LavalinkTrackFinish; g.musicInstance.lastSong = g.musicInstance.currentSong; g.musicInstance.currentSong = null; break; } case TrackEndReason.Replaced: { break; } case TrackEndReason.LoadFailed: { await g.musicInstance.usedChannel.SendMessageAsync(embed : new DiscordEmbedBuilder().WithTitle("Track failed to play") .WithDescription($"**{g.musicInstance.currentSong.track.Title}**\nby {g.musicInstance.currentSong.track.Author}\n" + $"**Failed to load, Skipping to next track**")); g.musicInstance.guildConnection.PlaybackFinished -= LavalinkTrackFinish; await Database.RemoveFromQueue(g.musicInstance.currentSong.position, e.Player.Guild); if (lastPlayedSongs.Count == 0) { await Database.AddToLPL(e.Player.Guild.Id, g.musicInstance.currentSong.track.TrackString); } else if (lastPlayedSongs[0].track.Uri != g.musicInstance.currentSong.track.Uri) { await Database.AddToLPL(e.Player.Guild.Id, g.musicInstance.currentSong.track.TrackString); } g.musicInstance.lastSong = g.musicInstance.currentSong; g.musicInstance.currentSong = null; var queue = await Database.GetQueue(e.Player.Guild); if (queue.Count != 0) { await g.musicInstance.PlaySong(); } else { g.musicInstance.playstate = Playstate.NotPlaying; } break; } case TrackEndReason.Finished: { g.musicInstance.guildConnection.PlaybackFinished -= LavalinkTrackFinish; if (g.musicInstance.repeatMode != RepeatMode.On && g.musicInstance.repeatMode != RepeatMode.All) { await Database.RemoveFromQueue(g.musicInstance.currentSong.position, e.Player.Guild); } if (lastPlayedSongs.Count == 0) { await Database.AddToLPL(e.Player.Guild.Id, g.musicInstance.currentSong.track.TrackString); } else if (lastPlayedSongs[0].track.Uri != g.musicInstance.currentSong.track.Uri) { await Database.AddToLPL(e.Player.Guild.Id, g.musicInstance.currentSong.track.TrackString); } g.musicInstance.lastSong = g.musicInstance.currentSong; g.musicInstance.currentSong = null; var queue = await Database.GetQueue(e.Player.Guild); if (queue.Count != 0) { await g.musicInstance.PlaySong(); } else { g.musicInstance.playstate = Playstate.NotPlaying; } break; } } } catch (Exception ex) { Bot.bot.Logger.LogError(ex.Message); Bot.bot.Logger.LogError(ex.StackTrace); } }
async Task OnPlaybackFinished(TrackFinishEventArgs e) { await Task.Delay(500); await this.NotifyNextTrackAsync(); }
private async Task PlayNextTrack(LavalinkGuildConnection lvc, TrackFinishEventArgs e) { if (e.Reason == TrackEndReason.Cleanup) { ShimakazeBot.SendToDebugRoom("Lavalink failed in **" + $"{e.Player.Guild.Name}** ({e.Player.Guild.Id}) - **" + $"{e.Player.Channel.Name}** ({e.Player.Channel.Id}) - song: " + e.Track.Title); ShimakazeBot.Client.Logger.Log(LogLevel.Warning, LogSources.PLAYLIST_NEXT_EVENT, $"{e.Reason} - playlist length at error: " + ShimakazeBot.playlists[e.Player.Guild].songRequests.Count); if (ShimakazeBot.playlists[e.Player.Guild].songRequests.Count > 0) { await ShimakazeBot.playlists[e.Player.Guild].songRequests[0].requestedChannel.SendMessageAsync( ShimakazeBot.playlists[e.Player.Guild].songRequests[0].requestMember.Mention + "Lavalink failed... Shima will leave the voice channel. " + "Don't worry your playlist has been saved. You can make her rejoin." + (ShimakazeBot.shouldSendToDebugRoom ? " The devs have been notified." : "")); await ForceLeave(e.Player.Guild); } return; } if (e.Reason == TrackEndReason.LoadFailed) { ShimakazeBot.Client.Logger.Log(LogLevel.Warning, LogSources.PLAYLIST_NEXT_EVENT, $"{e.Reason} - playlist length at error: " + ShimakazeBot.playlists[e.Player.Guild].songRequests.Count); } if (e.Reason == TrackEndReason.Replaced) { return; } if (ShimakazeBot.playlists[e.Player.Guild].songRequests.Count <= 0) { return; } if (ShimakazeBot.playlists[e.Player.Guild].loopCount > 0) { ShimakazeBot.playlists[e.Player.Guild].loopCount--; await e.Player.PlayAsync(e.Track); return; } ShimakazeBot.playlists[e.Player.Guild].songRequests.RemoveAt(0); ShimakazeBot.playlists[e.Player.Guild].voteSkip = null; ShimakazeBot.Client.Logger.Log(LogLevel.Information, LogSources.PLAYLIST_NEXT_EVENT, $"{e.Reason} - " + $"{ShimakazeBot.playlists[e.Player.Guild].songRequests.Count} " + $"songs remaining in {e.Player.Guild.Name}."); if (ShimakazeBot.playlists[e.Player.Guild].songRequests.Count > 0) { await e.Player.PlayAsync(ShimakazeBot.playlists[e.Player.Guild].songRequests.First().track); if (ShimakazeBot.CheckDebugMode(e.Player.Guild.Id)) { ShimakazeBot.Client.Logger.Log(LogLevel.Information, $"{LogSources.PLAYLIST_NEXT_EVENT} SupaDebug @{e.Player.Guild.Name}", "next track: " + ShimakazeBot.lvn.GetGuildConnection(e.Player.Guild)?.CurrentState?.CurrentTrack?.Title); } } return; }
private async Task Player_PlaybackFinished(TrackFinishEventArgs e) { await Task.Delay(500).ConfigureAwait(false); this.PlayHandler(); }
public async Task PlayFin(TrackFinishEventArgs lg) { Console.WriteLine(lg.Reason); Console.WriteLine(lg.Track.Author); Console.WriteLine(lg.Track.Title); Console.WriteLine(lg.Track.Uri); Console.WriteLine("End Event"); var con = Bot.guit[0].LLinkCon; var pos = Bot.guit.FindIndex(x => x.GID == lg.Player.Guild.Id); if (pos == -1 || !con.IsConnected || con == null) { await Task.CompletedTask; return; } if (lg.Reason == TrackEndReason.LoadFailed) { try { Bot.guit[pos].queue.RemoveAt(Bot.guit[pos].queue.FindIndex(x => x.addtime == Bot.guit[pos].playnow.addtime)); } catch { } await lg.Player.Guild.GetChannel(Bot.guit[pos].cmdChannel).SendMessageAsync("Track error, maybe regionlocked, skipped >>"); Console.WriteLine($"[{lg.Player.Guild.Id}] Song errored/regionblocked"); await Task.CompletedTask; return; } if (lg.Track.IsStream && lg.Reason != TrackEndReason.Stopped) { Bot.guit[pos].sstop = false; Bot.guit[pos].LLGuild.Play(Bot.guit[pos].playnow.LavaTrack); Console.WriteLine("LL Stream Error"); await Task.CompletedTask; return; } if (!Bot.guit[pos].repeat && !Bot.guit[pos].repeatAll && Bot.guit[pos].LLGuild != null && !Bot.guit[pos].sstop) { Bot.guit[pos].queue.Remove(Bot.guit[pos].queue.Find(x => x.addtime == Bot.guit[pos].playnow.addtime)); } if (Bot.guit[pos].sstop) { Bot.guit[pos].sstop = false; Bot.guit[pos].playing = false; } else if (Bot.guit[pos].queue.Count != 0) { Bot.guit[pos].playing = true; Bot.guit[pos].paused = false; await setPlay(pos); int nextSong = 0; System.Random rnd = new System.Random(); if (Bot.guit[pos].shuffle) nextSong = rnd.Next(0, Bot.guit[pos].queue.Count); if (Bot.guit[pos].repeatAll) { Bot.guit[pos].rAint++; nextSong = Bot.guit[pos].rAint; if (Bot.guit[pos].rAint == Bot.guit[pos].queue.Count) { Bot.guit[pos].rAint = 0; nextSong = 0; } } await setNP(pos, Bot.guit[pos].queue[nextSong]); Console.WriteLine($"[{lg.Player.Guild.Id}] Playing {Bot.guit[pos].playnow.LavaTrack.Title} by {Bot.guit[pos].playnow.LavaTrack.Author}"); Bot.guit[pos].LLGuild.Play(Bot.guit[pos].playnow.LavaTrack); var Recover = PlayRecover(Bot.guit[pos]); Recover.Wait(1000); } else { Bot.guit[pos].paused = false; Bot.guit[pos].playing = false; } await Task.CompletedTask; }
async Task Connection_PlaybackFinished(TrackFinishEventArgs e) { await Task.Delay(500).ConfigureAwait(false); BeginPlay(); }
async Task PlaybackFinished(TrackFinishEventArgs e) => await this.NotifyNextTrackAsync();
public static async Task TrackEnd(LavalinkGuildConnection c, TrackFinishEventArgs lg) { Console.WriteLine(lg.Reason); Console.WriteLine(lg.Track.IsStream); if (lg.Reason == TrackEndReason.Finished && lg.Player.CurrentState.CurrentTrack.IsStream) { await Bot.Guilds[lg.Player.Guild.Id].GuildConnection.PlayAsync(Bot.Guilds[lg.Player.Guild.Id].CurrentSong.Track); } else if (lg.Reason == TrackEndReason.Finished && !Bot.Guilds[lg.Player.Guild.Id].Stop || lg.Reason == TrackEndReason.LoadFailed && !Bot.Guilds[lg.Player.Guild.Id].Stop) { if (lg.Reason == TrackEndReason.LoadFailed) { await lg.Player.Guild.GetChannel(Bot.Guilds[lg.Player.Guild.Id].UsedChannel).SendMessageAsync("Track failed to load, so it got skipped"); } if (!Bot.Guilds[lg.Player.Guild.Id].Repeat && !Bot.Guilds[lg.Player.Guild.Id].RepeatAll && Bot.Guilds[lg.Player.Guild.Id].GuildConnection != null) { try { Bot.Guilds[lg.Player.Guild.Id].Queue.Remove(Bot.Guilds[lg.Player.Guild.Id].Queue.First(x => x.RequestTime == Bot.Guilds[lg.Player.Guild.Id].CurrentSong.RequestTime)); } catch { } } if (Bot.Guilds[lg.Player.Guild.Id].Queue.Count > 0 && Bot.Guilds[lg.Player.Guild.Id].GuildConnection?.IsConnected == true) { int nextSong = 0; Random rnd = new Random(); if (Bot.Guilds[lg.Player.Guild.Id].RepeatAll) { Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition++; nextSong = Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition; if (Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition == Bot.Guilds[lg.Player.Guild.Id].Queue.Count) { Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition = 0; nextSong = 0; } } if (Bot.Guilds[lg.Player.Guild.Id].Shuffle) { nextSong = rnd.Next(0, Bot.Guilds[lg.Player.Guild.Id].Queue.Count); } Bot.Guilds[lg.Player.Guild.Id].CurrentSong = Bot.Guilds[lg.Player.Guild.Id].Queue[nextSong]; await Bot.Guilds[lg.Player.Guild.Id].GuildConnection.PlayAsync(Bot.Guilds[lg.Player.Guild.Id].Queue[nextSong].Track); } else { Bot.Guilds[lg.Player.Guild.Id].Playing = false; } } else if (lg.Reason == TrackEndReason.Stopped && Bot.Guilds[lg.Player.Guild.Id].Stop) { Bot.Guilds[lg.Player.Guild.Id].Playing = false; Bot.Guilds[lg.Player.Guild.Id].Stop = false; } else if (lg.Reason == TrackEndReason.Replaced) { Bot.Guilds[lg.Player.Guild.Id].Stop = false; } else { Bot.Guilds[lg.Player.Guild.Id].Playing = false; Bot.Guilds[lg.Player.Guild.Id].Stop = false; } await Task.FromResult(true); }
private async Task LavalinkVoice_PlaybackFinished(LavalinkGuildConnection ll, TrackFinishEventArgs e) { if (this.ContextChannel == null) { return; } await this.ContextChannel.SendMessageAsync($"Playback of {Formatter.Bold(Formatter.Sanitize(e.Track.Title))} by {Formatter.Bold(Formatter.Sanitize(e.Track.Author))} finished.").ConfigureAwait(false); this.ContextChannel = null; }
public static Task TrackEnd(TrackFinishEventArgs lg) { Console.WriteLine(lg.Reason); Console.WriteLine(lg.Track.IsStream); if (lg.Reason == TrackEndReason.Finished && lg.Player.CurrentState.CurrentTrack.IsStream) { var Next = Bot.Guilds[lg.Player.Guild.Id].CurrentSong.Track; //var e = Utilities.GetTrackByURL(Bot.Guilds[lg.Player.Guild.Id].CurrentSong.Track.Uri.OriginalString, Bot.Guilds[lg.Player.Guild.Id].ShardID); //e.Wait(); //Next = e.Result.First(); ; Bot.Guilds[lg.Player.Guild.Id].GuildConnection.Play(Next); } else if (lg.Reason == TrackEndReason.Finished && !Bot.Guilds[lg.Player.Guild.Id].Stop || lg.Reason == TrackEndReason.LoadFailed && !Bot.Guilds[lg.Player.Guild.Id].Stop) { if (lg.Reason == TrackEndReason.LoadFailed) { lg.Player.Guild.GetChannel(Bot.Guilds[lg.Player.Guild.Id].UsedChannel).SendMessageAsync("Track failed to load, so it got skipped"); } if (!Bot.Guilds[lg.Player.Guild.Id].Repeat && !Bot.Guilds[lg.Player.Guild.Id].RepeatAll && Bot.Guilds[lg.Player.Guild.Id].GuildConnection != null) { try { Bot.Guilds[lg.Player.Guild.Id].Queue.Remove(Bot.Guilds[lg.Player.Guild.Id].Queue.First(x => x.RequestTime == Bot.Guilds[lg.Player.Guild.Id].CurrentSong.RequestTime)); } catch { } } if (Bot.Guilds[lg.Player.Guild.Id].Queue.Count > 0 && Bot.Guilds[lg.Player.Guild.Id].GuildConnection?.IsConnected == true) { int nextSong = 0; Random rnd = new Random(); if (Bot.Guilds[lg.Player.Guild.Id].RepeatAll) { Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition++; nextSong = Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition; if (Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition == Bot.Guilds[lg.Player.Guild.Id].Queue.Count) { Bot.Guilds[lg.Player.Guild.Id].RepeatAllPosition = 0; nextSong = 0; } } if (Bot.Guilds[lg.Player.Guild.Id].Shuffle) { nextSong = rnd.Next(0, Bot.Guilds[lg.Player.Guild.Id].Queue.Count); while ((Bot.Guilds[lg.Player.Guild.Id].Queue[nextSong] == Bot.Guilds[lg.Player.Guild.Id].CurrentSong) && Bot.Guilds[lg.Player.Guild.Id].Queue.Count != 1) { nextSong = rnd.Next(0, Bot.Guilds[lg.Player.Guild.Id].Queue.Count); } } Bot.Guilds[lg.Player.Guild.Id].CurrentSong = Bot.Guilds[lg.Player.Guild.Id].Queue[nextSong]; var Next = Bot.Guilds[lg.Player.Guild.Id].CurrentSong.Track; if (Next.IsStream) { //var e = Utilities.GetTrackByURL(Bot.Guilds[lg.Player.Guild.Id].CurrentSong.Track.Uri.OriginalString, Bot.Guilds[lg.Player.Guild.Id].ShardID); //e.Wait(); //Next = e.Result.First(); } Bot.Guilds[lg.Player.Guild.Id].GuildConnection.Play(Next); } else { Bot.Guilds[lg.Player.Guild.Id].Playing = false; } } else if (lg.Reason == TrackEndReason.Stopped && Bot.Guilds[lg.Player.Guild.Id].Stop) { Bot.Guilds[lg.Player.Guild.Id].Playing = false; Bot.Guilds[lg.Player.Guild.Id].Stop = false; } else if (lg.Reason == TrackEndReason.Replaced) { Bot.Guilds[lg.Player.Guild.Id].Stop = false; } else { Bot.Guilds[lg.Player.Guild.Id].Playing = false; Bot.Guilds[lg.Player.Guild.Id].Stop = false; } return(Task.CompletedTask); }