Music format
This commit is contained in:
parent
ed505a7809
commit
1d2e44c7be
@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Music
|
namespace NadekoBot.Modules.Music
|
||||||
{
|
{
|
||||||
@ -31,12 +32,12 @@ namespace NadekoBot.Modules.Music
|
|||||||
//it can fail if its currenctly opened or doesn't exist. Either way i don't care
|
//it can fail if its currenctly opened or doesn't exist. Either way i don't care
|
||||||
try { Directory.Delete(MusicDataPath, true); } catch { }
|
try { Directory.Delete(MusicDataPath, true); } catch { }
|
||||||
|
|
||||||
NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
|
NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
|
||||||
|
|
||||||
Directory.CreateDirectory(MusicDataPath);
|
Directory.CreateDirectory(MusicDataPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
|
private async Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
|
||||||
{
|
{
|
||||||
var usr = iusr as SocketGuildUser;
|
var usr = iusr as SocketGuildUser;
|
||||||
if (usr == null ||
|
if (usr == null ||
|
||||||
@ -100,7 +101,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) return Task.CompletedTask;
|
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) return Task.CompletedTask;
|
||||||
if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
||||||
if(MusicPlayers.TryRemove(Context.Guild.Id, out musicPlayer))
|
if (MusicPlayers.TryRemove(Context.Guild.Id, out musicPlayer))
|
||||||
musicPlayer.Destroy();
|
musicPlayer.Destroy();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
@ -165,7 +166,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
|
|
||||||
//var toSend = $"🎵 Currently Playing {currentSong.PrettyName} " + $"`{currentSong.PrettyCurrentTime()}`\n";
|
//var toSend = $"🎵 Currently Playing {currentSong.PrettyName} " + $"`{currentSong.PrettyCurrentTime()}`\n";
|
||||||
var toSend = $"🎵 Currently Playing {currentSong.PrettyName}\n";
|
var toSend = $"🎵 Currently Playing {currentSong.PrettyName}\n";
|
||||||
if (musicPlayer.RepeatSong)
|
if (musicPlayer.RepeatSong)
|
||||||
toSend += "🔂";
|
toSend += "🔂";
|
||||||
else if (musicPlayer.RepeatPlaylist)
|
else if (musicPlayer.RepeatPlaylist)
|
||||||
@ -191,28 +192,28 @@ namespace NadekoBot.Modules.Music
|
|||||||
var currentSong = musicPlayer.CurrentSong;
|
var currentSong = musicPlayer.CurrentSong;
|
||||||
if (currentSong == null)
|
if (currentSong == null)
|
||||||
return;
|
return;
|
||||||
var videoid = Regex.Match(currentSong.SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+");
|
var videoid = Regex.Match(currentSong.SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+");
|
||||||
|
|
||||||
if (currentSong.TotalLength == TimeSpan.Zero)
|
if (currentSong.TotalLength == TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false);
|
await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
var embed = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
.WithAuthor(eab => eab.WithName("Now Playing").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png"))
|
.WithAuthor(eab => eab.WithName("Now Playing").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png"))
|
||||||
.WithTitle($"{currentSong.SongInfo.Title}")
|
.WithTitle($"{currentSong.SongInfo.Title}")
|
||||||
.WithUrl($"{currentSong.SongInfo.Query}")
|
.WithUrl($"{currentSong.SongInfo.Query}")
|
||||||
.WithDescription($"{currentSong.PrettyCurrentTime()}")
|
.WithDescription($"{currentSong.PrettyCurrentTime()}")
|
||||||
.WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyUser}"))
|
.WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyUser}"))
|
||||||
.WithColor(NadekoBot.OkColor);
|
.WithColor(NadekoBot.OkColor);
|
||||||
if (currentSong.SongInfo.Provider.Equals("YouTube", StringComparison.OrdinalIgnoreCase))
|
if (currentSong.SongInfo.Provider.Equals("YouTube", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
embed.WithThumbnailUrl($"https://img.youtube.com/vi/{videoid}/0.jpg");
|
embed.WithThumbnailUrl($"https://img.youtube.com/vi/{videoid}/0.jpg");
|
||||||
}
|
}
|
||||||
else if (currentSong.SongInfo.Provider.Equals("SoundCloud", StringComparison.OrdinalIgnoreCase))
|
else if (currentSong.SongInfo.Provider.Equals("SoundCloud", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
embed.WithThumbnailUrl($"{currentSong.SongInfo.AlbumArt}");
|
embed.WithThumbnailUrl($"{currentSong.SongInfo.AlbumArt}");
|
||||||
}
|
}
|
||||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -298,15 +299,22 @@ namespace NadekoBot.Modules.Music
|
|||||||
var count = idArray.Length;
|
var count = idArray.Length;
|
||||||
var msg =
|
var msg =
|
||||||
await Context.Channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false);
|
await Context.Channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false);
|
||||||
foreach (var id in idArray)
|
var cancelSource = new CancellationTokenSource();
|
||||||
|
|
||||||
|
var tasks = Task.WhenAll(idArray.Select(async id =>
|
||||||
{
|
{
|
||||||
|
if (cancelSource.Token.IsCancellationRequested)
|
||||||
|
return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, id, true).ConfigureAwait(false);
|
await QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, id, true).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (SongNotFoundException) { }
|
catch (SongNotFoundException) { }
|
||||||
catch { break; }
|
catch { try { cancelSource.Cancel(); } catch { } }
|
||||||
}
|
}));
|
||||||
|
|
||||||
|
await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token));
|
||||||
|
|
||||||
await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false);
|
await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,7 +565,8 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
var curSong = musicPlayer.CurrentSong;
|
var curSong = musicPlayer.CurrentSong;
|
||||||
var songs = musicPlayer.Playlist.Append(curSong)
|
var songs = musicPlayer.Playlist.Append(curSong)
|
||||||
.Select(s=> new PlaylistSong() {
|
.Select(s => new PlaylistSong()
|
||||||
|
{
|
||||||
Provider = s.SongInfo.Provider,
|
Provider = s.SongInfo.Provider,
|
||||||
ProviderType = s.SongInfo.ProviderType,
|
ProviderType = s.SongInfo.ProviderType,
|
||||||
Title = s.SongInfo.Title,
|
Title = s.SongInfo.Title,
|
||||||
@ -677,8 +686,6 @@ namespace NadekoBot.Modules.Music
|
|||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Goto(int time)
|
public async Task Goto(int time)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
|
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
|
||||||
return;
|
return;
|
||||||
@ -779,7 +786,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
var mp = new MusicPlayer(voiceCh, vol);
|
var mp = new MusicPlayer(voiceCh, vol);
|
||||||
IUserMessage playingMessage = null;
|
IUserMessage playingMessage = null;
|
||||||
IUserMessage lastFinishedMessage = null;
|
IUserMessage lastFinishedMessage = null;
|
||||||
mp.OnCompleted += async (s, song) =>
|
mp.OnCompleted += async (s, song) =>
|
||||||
{
|
{
|
||||||
if (song.PrintStatusMessage)
|
if (song.PrintStatusMessage)
|
||||||
@ -807,21 +814,21 @@ namespace NadekoBot.Modules.Music
|
|||||||
if (sender == null)
|
if (sender == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var msgTxt = $"🎵 Playing {song.PrettyName}\t `Vol: {(int)(sender.Volume * 100)}%`";
|
var msgTxt = $"🎵 Playing {song.PrettyName}\t `Vol: {(int)(sender.Volume * 100)}%`";
|
||||||
try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { }
|
try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mp.OnPauseChanged += async (paused) =>
|
mp.OnPauseChanged += async (paused) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (paused)
|
if (paused)
|
||||||
await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false);
|
await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
|
await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
};
|
};
|
||||||
return mp;
|
return mp;
|
||||||
});
|
});
|
||||||
Song resolvedSong;
|
Song resolvedSong;
|
||||||
|
Loading…
Reference in New Issue
Block a user