6 Commits

Author SHA1 Message Date
EkiciLP
ac0f6e18ed fixed stage channel speaking requests
fixed several bugs regarding autoplay

fixed skip autoplay not working
2022-04-15 02:28:20 +02:00
EkiciLP
47bffbff7f fix Bot throwing an error when tryimg to autoplay tracks from non youtube sources 2022-04-14 12:13:39 +02:00
Tim Müller
fcd376bdcb fix Queue Loop Current track not prepending on enable but appending 2022-04-13 11:24:59 +02:00
Tim Müller
a71f65de55 update package sources 2022-04-06 21:32:43 +02:00
Tim Müller
3fd19eb149 fix playlist playback nicely 2022-04-01 18:53:07 +02:00
Tim Müller
bc7e493e71 fix playlist playback not working 2022-04-01 18:46:03 +02:00
7 changed files with 53 additions and 57 deletions

View File

@@ -46,9 +46,9 @@ namespace TomatenMusic_Api
if (e.Response.IsPlaylist)
{
if (e.Now)
await player.PlayPlaylistNowAsync(e.Response.Playlist);
await player.PlayNowAsync(e.Response.Playlist);
else
await player.PlayPlaylistAsync(e.Response.Playlist);
await player.PlayItemAsync(e.Response.Playlist);
}else
{
if (e.Now)

View File

@@ -5,10 +5,6 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>TomatenMusic_Api</RootNamespace>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://nuget.emzi0767.com/api/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>

View File

@@ -84,7 +84,7 @@ namespace TomatenMusic.Commands
if (response.IsPlaylist)
{
ILavalinkPlaylist playlist = response.Playlist;
await player.PlayPlaylistNowAsync(playlist);
await player.PlayNowAsync(playlist);
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed(
Common.AsEmbed(playlist)
@@ -237,7 +237,7 @@ namespace TomatenMusic.Commands
if (response.IsPlaylist)
{
ILavalinkPlaylist playlist = response.Playlist;
await player.PlayPlaylistAsync(playlist);
await player.PlayItemAsync(playlist);
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed(
Common.AsEmbed(playlist)

View File

@@ -64,26 +64,6 @@ namespace TomatenMusic.Music
QueuePrompt.UpdateFor(GuildId);
}
public async Task PlayPlaylistAsync(ILavalinkPlaylist playlist)
{
EnsureNotDestroyed();
EnsureConnected();
_logger.LogInformation("Started playing Playlist {0} on Guild {1}", playlist.Title, (await GetGuildAsync()).Name);
QueuePrompt.UpdateFor(GuildId);
}
public async Task PlayPlaylistNowAsync(ILavalinkPlaylist playlist)
{
EnsureConnected();
EnsureNotDestroyed();
QueuePrompt.UpdateFor(GuildId);
}
public async Task RewindAsync()
{
EnsureNotDestroyed();
@@ -109,17 +89,12 @@ namespace TomatenMusic.Music
MusicActionResponse response;
try
{
response = PlayerQueue.NextTrack(true);
response = PlayerQueue.NextTrack(true, Autoplay);
}catch (Exception ex)
{
if (Autoplay)
{
YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
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);
_ = OnAutoPlay(CurrentTrack);
return;
}
throw ex;
@@ -184,10 +159,16 @@ namespace TomatenMusic.Music
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");
}
await stageInstance.Channel.UpdateCurrentUserVoiceStateAsync(false);
}
@@ -223,7 +204,6 @@ namespace TomatenMusic.Music
public async override Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
{
DisconnectOnStop = false;
YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
var oldTrack = CurrentTrack;
if (eventArgs.Reason != TrackEndReason.Finished)
@@ -246,12 +226,8 @@ namespace TomatenMusic.Music
return;
}
TomatenMusicTrack 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}");
await base.OnTrackEndAsync(eventArgs);
PlayerQueue.LastTrack = newTrack;
await newTrack.Play(this);
QueuePrompt.UpdateFor(GuildId);
_ = OnAutoPlay(oldTrack);
}
}
@@ -259,6 +235,21 @@ namespace TomatenMusic.Music
}
public async Task OnAutoPlay(LavalinkTrack oldTrack)
{
YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
TomatenMusicTrack newTrack;
if (oldTrack.Provider != StreamProvider.YouTube)
newTrack = await youtube.GetRelatedTrackAsync(PlayerQueue.PlayedTracks.First(x => x.Provider == StreamProvider.YouTube).TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier));
else
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}");
PlayerQueue.LastTrack = newTrack;
await newTrack.PlayNow(this, withoutQueuePrepend: true);
QueuePrompt.UpdateFor(GuildId);
}
public async Task<DiscordChannel> GetChannelAsync()
{
EnsureConnected();

View File

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

View File

@@ -98,7 +98,10 @@ namespace TomatenMusic.Prompt.Implementation
await Player.RewindAsync();
}catch (Exception ex)
{
_ = args.Interaction.CreateResponseAsync(
DSharpPlus.InteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder()
.WithContent($"An Error occurred during this Interaction {ex.Message}"));
}
}
}
@@ -131,8 +134,18 @@ namespace TomatenMusic.Prompt.Implementation
_ = args.Interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().WithContent("Please connect to the bots Channel to use this Interaction"));
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);
timer.Elapsed += (s, args) =>

View File

@@ -4,17 +4,13 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://nuget.emzi0767.com/api/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.2.0-nightly-01101" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0-nightly-01101" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0-nightly-01101" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.56.0.2630" />
<PackageReference Include="DSharpPlus" Version="4.2.0-nightly-01107" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0-nightly-01107" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0-nightly-01107" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.57.0.2637" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
<PackageReference Include="Lavalink4NET" Version="2.1.1" />
<PackageReference Include="Lavalink4NET.DSharpPlus" Version="2.1.1" />