!!rm improved, both code and prettyness

This commit is contained in:
Kwoth 2017-01-03 15:46:16 +01:00
parent adb1e570dd
commit 520fbe917f
2 changed files with 25 additions and 16 deletions

View File

@ -77,6 +77,8 @@ namespace NadekoBot.Modules.Music.Classes
public string PrettyVolume => $"🔉 {(int)(Volume * 100)}%";
public event Action<Song> SongRemoved = delegate { };
public MusicPlayer(IVoiceChannel startingVoiceChannel, float? defaultVolume)
{
if (startingVoiceChannel == null)
@ -277,7 +279,12 @@ namespace NadekoBot.Modules.Music.Classes
{
if (index < 0 || index >= playlist.Count)
return;
playlist.RemoveAt(index);
var song = playlist.ElementAtOrDefault(index);
if (playlist.Remove(song))
{
SongRemoved(song);
}
});
}

View File

@ -461,27 +461,29 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota
public async Task Remove(int num)
{
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
{
return;
}
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return;
if (num <= 0 || num > musicPlayer.Playlist.Count)
return;
var song = (musicPlayer.Playlist as List<Song>)?[num - 1];
musicPlayer.RemoveSongAt(num - 1);
musicPlayer.SongRemoved += async (song) =>
{
try
{
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName("Song Removed!").WithMusicIcon())
.AddField(fb => fb.WithName("**Song Position**").WithValue($"#{num}").WithIsInline(true))
.AddField(fb => fb.WithName("**Song Name**").WithValue(song.PrettyName).WithIsInline(true))
.WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}"))
.WithAuthor(eab => eab.WithName("Removed song #" + num).WithMusicIcon())
.WithDescription(song.PrettyName)
.WithFooter(ef => ef.WithText(song.PrettyInfo))
.WithErrorColor();
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
catch { }
};
musicPlayer.RemoveSongAt(num - 1);
}
[NadekoCommand, Usage, Description, Aliases]