fixed stage channel speaking requests

fixed several bugs regarding autoplay

fixed skip autoplay not working
This commit is contained in:
EkiciLP 2022-04-15 02:28:20 +02:00
parent 47bffbff7f
commit ac0f6e18ed
3 changed files with 31 additions and 16 deletions

@ -89,17 +89,12 @@ namespace TomatenMusic.Music
MusicActionResponse response; MusicActionResponse response;
try try
{ {
response = PlayerQueue.NextTrack(true); response = PlayerQueue.NextTrack(true, Autoplay);
}catch (Exception ex) }catch (Exception ex)
{ {
if (Autoplay) if (Autoplay)
{ {
YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>(); _ = OnAutoPlay(CurrentTrack);
LavalinkTrack newTrack = await youtube.GetRelatedTrackAsync(CurrentTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier));
_logger.LogInformation($"Skipped Track {CurrentTrack.Title} for Autoplayed Track {newTrack.Title}");
await PlayAsync(newTrack);
QueuePrompt.UpdateFor(GuildId);
return; return;
} }
throw ex; throw ex;
@ -164,10 +159,16 @@ namespace TomatenMusic.Music
if (channel.Type == ChannelType.Stage) if (channel.Type == ChannelType.Stage)
{ {
DiscordStageInstance stageInstance = await channel.GetStageInstanceAsync(); DiscordStageInstance stageInstance;
try
{
stageInstance = await channel.GetStageInstanceAsync();
if (stageInstance == null) }catch (Exception ex)
{
stageInstance = await channel.CreateStageInstanceAsync("Music"); stageInstance = await channel.CreateStageInstanceAsync("Music");
}
await stageInstance.Channel.UpdateCurrentUserVoiceStateAsync(false); await stageInstance.Channel.UpdateCurrentUserVoiceStateAsync(false);
} }
@ -239,13 +240,13 @@ namespace TomatenMusic.Music
YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>(); YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
TomatenMusicTrack newTrack; TomatenMusicTrack newTrack;
if (oldTrack.Source != "YouTube" ) if (oldTrack.Provider != StreamProvider.YouTube)
newTrack = await youtube.GetRelatedTrackAsync(PlayerQueue.PlayedTracks.First(x => x.Source == "YouTube").TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier)); newTrack = await youtube.GetRelatedTrackAsync(PlayerQueue.PlayedTracks.First(x => x.Provider == StreamProvider.YouTube).TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier));
else else
newTrack = await youtube.GetRelatedTrackAsync(oldTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier)); newTrack = await youtube.GetRelatedTrackAsync(oldTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier));
_logger.LogInformation($"Autoplaying for track {oldTrack.TrackIdentifier} with Track {newTrack.TrackIdentifier}"); _logger.LogInformation($"Autoplaying for track {oldTrack.TrackIdentifier} with Track {newTrack.TrackIdentifier}");
PlayerQueue.LastTrack = newTrack; PlayerQueue.LastTrack = newTrack;
await newTrack.Play(this); await newTrack.PlayNow(this, withoutQueuePrepend: true);
QueuePrompt.UpdateFor(GuildId); QueuePrompt.UpdateFor(GuildId);
} }

@ -92,9 +92,10 @@ namespace TomatenMusic.Music
} }
public MusicActionResponse NextTrack(bool ignoreLoop = false) public MusicActionResponse NextTrack(bool ignoreLoop = false, bool autoplay = false)
{ {
if (LastTrack != null) if (LastTrack != null)
if (LoopType != LoopType.NONE && Queue.Count == 0 || autoplay)
PlayedTracks = new Queue<TomatenMusicTrack>(PlayedTracks.Prepend(new TomatenMusicTrack(LastTrack.WithPosition(TimeSpan.Zero)))); PlayedTracks = new Queue<TomatenMusicTrack>(PlayedTracks.Prepend(new TomatenMusicTrack(LastTrack.WithPosition(TimeSpan.Zero))));
switch (LoopType) switch (LoopType)

@ -98,7 +98,10 @@ namespace TomatenMusic.Prompt.Implementation
await Player.RewindAsync(); await Player.RewindAsync();
}catch (Exception ex) }catch (Exception ex)
{ {
_ = args.Interaction.CreateResponseAsync(
DSharpPlus.InteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder()
.WithContent($"An Error occurred during this Interaction {ex.Message}"));
} }
} }
} }
@ -131,9 +134,19 @@ namespace TomatenMusic.Prompt.Implementation
_ = args.Interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().WithContent("Please connect to the bots Channel to use this Interaction")); _ = args.Interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().WithContent("Please connect to the bots Channel to use this Interaction"));
return; return;
} }
try
{
await Player.SkipAsync(); await Player.SkipAsync();
}
catch (Exception ex)
{
_ = args.Interaction.CreateResponseAsync(
DSharpPlus.InteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder()
.WithContent($"An Error occurred during this Interaction {ex.Message}"));
}
System.Timers.Timer timer = new System.Timers.Timer(800); System.Timers.Timer timer = new System.Timers.Timer(800);
timer.Elapsed += (s, args) => timer.Elapsed += (s, args) =>
{ {