.movesong works more intuitively now, and current song's index is now updated after songs are moved

This commit is contained in:
Master Kwoth 2017-07-13 04:09:21 +02:00
parent b85cc023f2
commit ed40bc99b2
2 changed files with 19 additions and 8 deletions

View File

@ -774,7 +774,7 @@ namespace NadekoBot.Modules.Music
SongInfo s; SongInfo s;
if (fromtoArr.Length != 2 || !int.TryParse(fromtoArr[0], out var n1) || if (fromtoArr.Length != 2 || !int.TryParse(fromtoArr[0], out var n1) ||
!int.TryParse(fromtoArr[1], out var n2) || n1 < 1 || n2 < 1 || n1 == n2 !int.TryParse(fromtoArr[1], out var n2) || n1 < 1 || n2 < 1 || n1 == n2
|| (s = mp.MoveSong(n1, n2)) == null) || (s = mp.MoveSong(--n1, --n2)) == null)
{ {
await ReplyConfirmLocalized("invalid_input").ConfigureAwait(false); await ReplyConfirmLocalized("invalid_input").ConfigureAwait(false);
return; return;
@ -784,8 +784,8 @@ namespace NadekoBot.Modules.Music
.WithTitle(s.Title.TrimTo(65)) .WithTitle(s.Title.TrimTo(65))
.WithUrl(s.SongUrl) .WithUrl(s.SongUrl)
.WithAuthor(eab => eab.WithName(GetText("song_moved")).WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) .WithAuthor(eab => eab.WithName(GetText("song_moved")).WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png"))
.AddField(fb => fb.WithName(GetText("from_position")).WithValue($"#{n1}").WithIsInline(true)) .AddField(fb => fb.WithName(GetText("from_position")).WithValue($"#{n1 + 1}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("to_position")).WithValue($"#{n2}").WithIsInline(true)) .AddField(fb => fb.WithName(GetText("to_position")).WithValue($"#{n2 + 1}").WithIsInline(true))
.WithColor(NadekoBot.OkColor); .WithColor(NadekoBot.OkColor);
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
} }

View File

@ -153,14 +153,22 @@ namespace NadekoBot.Services.Music
{ {
lock (locker) lock (locker)
{ {
var currentSong = Current.Song;
var playlist = Songs.ToList(); var playlist = Songs.ToList();
if (n1 > playlist.Count || n2 > playlist.Count) if (n1 >= playlist.Count || n2 >= playlist.Count || n1 == n2)
return null; return null;
var s = playlist[n1 - 1];
playlist.Insert(n2 - 1, s); var s = playlist[n1];
var nn1 = n2 < n1 ? n1 : n1 - 1;
playlist.RemoveAt(nn1); playlist.RemoveAt(n1);
playlist.Insert(n2, s);
Songs = new LinkedList<SongInfo>(playlist); Songs = new LinkedList<SongInfo>(playlist);
if (currentSong != null)
CurrentIndex = playlist.IndexOf(currentSong);
return s; return s;
} }
} }
@ -180,3 +188,6 @@ namespace NadekoBot.Services.Music
} }
} }
} }
//O O [O] O O O O
//
// 3