.movesong works more intuitively now, and current song's index is now updated after songs are moved
This commit is contained in:
parent
b85cc023f2
commit
ed40bc99b2
@ -774,7 +774,7 @@ namespace NadekoBot.Modules.Music
|
||||
SongInfo s;
|
||||
if (fromtoArr.Length != 2 || !int.TryParse(fromtoArr[0], out var n1) ||
|
||||
!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);
|
||||
return;
|
||||
@ -784,8 +784,8 @@ namespace NadekoBot.Modules.Music
|
||||
.WithTitle(s.Title.TrimTo(65))
|
||||
.WithUrl(s.SongUrl)
|
||||
.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("to_position")).WithValue($"#{n2}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName(GetText("from_position")).WithValue($"#{n1 + 1}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName(GetText("to_position")).WithValue($"#{n2 + 1}").WithIsInline(true))
|
||||
.WithColor(NadekoBot.OkColor);
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
|
@ -153,14 +153,22 @@ namespace NadekoBot.Services.Music
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var currentSong = Current.Song;
|
||||
var playlist = Songs.ToList();
|
||||
if (n1 > playlist.Count || n2 > playlist.Count)
|
||||
if (n1 >= playlist.Count || n2 >= playlist.Count || n1 == n2)
|
||||
return null;
|
||||
var s = playlist[n1 - 1];
|
||||
playlist.Insert(n2 - 1, s);
|
||||
var nn1 = n2 < n1 ? n1 : n1 - 1;
|
||||
playlist.RemoveAt(nn1);
|
||||
|
||||
var s = playlist[n1];
|
||||
|
||||
playlist.RemoveAt(n1);
|
||||
playlist.Insert(n2, s);
|
||||
|
||||
Songs = new LinkedList<SongInfo>(playlist);
|
||||
|
||||
|
||||
if (currentSong != null)
|
||||
CurrentIndex = playlist.IndexOf(currentSong);
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@ -180,3 +188,6 @@ namespace NadekoBot.Services.Music
|
||||
}
|
||||
}
|
||||
}
|
||||
//O O [O] O O O O
|
||||
//
|
||||
// 3
|
Loading…
Reference in New Issue
Block a user