.ms readded
This commit is contained in:
parent
c33c2bce60
commit
9bb8f3d666
@ -45,6 +45,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
var t = _music.DestroyPlayer(arg.Id);
|
var t = _music.DestroyPlayer(arg.Id);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo changing server region is bugged again
|
//todo changing server region is bugged again
|
||||||
private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
|
private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
|
||||||
{
|
{
|
||||||
@ -725,7 +726,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public void Move()
|
public async Task Move()
|
||||||
{
|
{
|
||||||
var vch = ((IGuildUser)Context.User).VoiceChannel;
|
var vch = ((IGuildUser)Context.User).VoiceChannel;
|
||||||
|
|
||||||
@ -737,53 +738,42 @@ namespace NadekoBot.Modules.Music
|
|||||||
if (mp == null)
|
if (mp == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mp.SetVoiceChannel(vch);
|
await mp.SetVoiceChannel(vch);
|
||||||
}
|
}
|
||||||
|
|
||||||
//[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
//[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
//public async Task MoveSong([Remainder] string fromto)
|
public async Task MoveSong([Remainder] string fromto)
|
||||||
//{
|
{
|
||||||
// if (string.IsNullOrWhiteSpace(fromto))
|
if (string.IsNullOrWhiteSpace(fromto))
|
||||||
// return;
|
return;
|
||||||
|
|
||||||
// MusicPlayer musicPlayer;
|
MusicPlayer mp = _music.GetPlayerOrDefault(Context.Guild.Id);
|
||||||
// if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
if (mp == null)
|
||||||
// return;
|
return;
|
||||||
|
|
||||||
// fromto = fromto?.Trim();
|
fromto = fromto?.Trim();
|
||||||
// var fromtoArr = fromto.Split('>');
|
var fromtoArr = fromto.Split('>');
|
||||||
|
|
||||||
// int n1;
|
SongInfo s;
|
||||||
// int n2;
|
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)
|
||||||
|
{
|
||||||
|
await ReplyConfirmLocalized("invalid_input").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// var playlist = musicPlayer.Playlist as List<Song> ?? musicPlayer.Playlist.ToList();
|
var embed = new EmbedBuilder()
|
||||||
|
.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))
|
||||||
|
.WithColor(NadekoBot.OkColor);
|
||||||
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
// if (fromtoArr.Length != 2 || !int.TryParse(fromtoArr[0], out n1) ||
|
|
||||||
// !int.TryParse(fromtoArr[1], out n2) || n1 < 1 || n2 < 1 || n1 == n2 ||
|
|
||||||
// n1 > playlist.Count || n2 > playlist.Count)
|
|
||||||
// {
|
|
||||||
// await ReplyConfirmLocalized("invalid_input").ConfigureAwait(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var s = playlist[n1 - 1];
|
|
||||||
// playlist.Insert(n2 - 1, s);
|
|
||||||
// var nn1 = n2 < n1 ? n1 : n1 - 1;
|
|
||||||
// playlist.RemoveAt(nn1);
|
|
||||||
|
|
||||||
// var embed = new EmbedBuilder()
|
|
||||||
// .WithTitle($"{s.SongInfo.Title.TrimTo(70)}")
|
|
||||||
// .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))
|
|
||||||
// .WithColor(NadekoBot.OkColor);
|
|
||||||
// await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// //await channel.SendConfirmAsync($"🎵Moved {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false);
|
|
||||||
//}
|
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task SetMaxQueue(uint size = 0)
|
public async Task SetMaxQueue(uint size = 0)
|
||||||
|
@ -365,7 +365,6 @@ namespace NadekoBot.Services.Music
|
|||||||
|
|
||||||
public int Enqueue(SongInfo song)
|
public int Enqueue(SongInfo song)
|
||||||
{
|
{
|
||||||
_log.Info("Adding song");
|
|
||||||
lock (locker)
|
lock (locker)
|
||||||
{
|
{
|
||||||
if (Exited)
|
if (Exited)
|
||||||
@ -547,7 +546,7 @@ namespace NadekoBot.Services.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVoiceChannel(IVoiceChannel vch)
|
public async Task SetVoiceChannel(IVoiceChannel vch)
|
||||||
{
|
{
|
||||||
lock (locker)
|
lock (locker)
|
||||||
{
|
{
|
||||||
@ -555,6 +554,7 @@ namespace NadekoBot.Services.Music
|
|||||||
return;
|
return;
|
||||||
VoiceChannel = vch;
|
VoiceChannel = vch;
|
||||||
}
|
}
|
||||||
|
_audioClient = await vch.ConnectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateSongDurationsAsync()
|
public async Task UpdateSongDurationsAsync()
|
||||||
@ -581,6 +581,9 @@ namespace NadekoBot.Services.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SongInfo MoveSong(int n1, int n2)
|
||||||
|
=> Queue.MoveSong(n1, n2);
|
||||||
|
|
||||||
//// this should be written better
|
//// this should be written better
|
||||||
//public TimeSpan TotalPlaytime =>
|
//public TimeSpan TotalPlaytime =>
|
||||||
// _playlist.Any(s => s.TotalTime == TimeSpan.MaxValue) ?
|
// _playlist.Any(s => s.TotalTime == TimeSpan.MaxValue) ?
|
||||||
|
@ -9,7 +9,7 @@ namespace NadekoBot.Services.Music
|
|||||||
{
|
{
|
||||||
public class MusicQueue : IDisposable
|
public class MusicQueue : IDisposable
|
||||||
{
|
{
|
||||||
private LinkedList<SongInfo> Songs { get; } = new LinkedList<SongInfo>();
|
private LinkedList<SongInfo> Songs { get; set; } = new LinkedList<SongInfo>();
|
||||||
private int _currentIndex = 0;
|
private int _currentIndex = 0;
|
||||||
public int CurrentIndex
|
public int CurrentIndex
|
||||||
{
|
{
|
||||||
@ -147,5 +147,21 @@ namespace NadekoBot.Services.Music
|
|||||||
CurrentIndex = new NadekoRandom().Next(Songs.Count);
|
CurrentIndex = new NadekoRandom().Next(Songs.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SongInfo MoveSong(int n1, int n2)
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
var playlist = Songs.ToList();
|
||||||
|
if (n1 > playlist.Count || n2 > playlist.Count)
|
||||||
|
return null;
|
||||||
|
var s = playlist[n1 - 1];
|
||||||
|
playlist.Insert(n2 - 1, s);
|
||||||
|
var nn1 = n2 < n1 ? n1 : n1 - 1;
|
||||||
|
playlist.RemoveAt(nn1);
|
||||||
|
Songs = new LinkedList<SongInfo>(playlist);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace NadekoBot.Services.Music
|
|||||||
|
|
||||||
public string SongUri { get; private set; }
|
public string SongUri { get; private set; }
|
||||||
|
|
||||||
private volatile bool restart = false;
|
//private volatile bool restart = false;
|
||||||
|
|
||||||
public SongBuffer(string songUri, string skipTo)
|
public SongBuffer(string songUri, string skipTo)
|
||||||
{
|
{
|
||||||
@ -50,11 +50,13 @@ namespace NadekoBot.Services.Music
|
|||||||
|
|
||||||
private void P_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
private void P_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(e.Data))
|
||||||
|
return;
|
||||||
_log.Error(">>> " + e.Data);
|
_log.Error(">>> " + e.Data);
|
||||||
if (e.Data?.Contains("Error in the pull function") == true)
|
if (e.Data?.Contains("Error in the pull function") == true)
|
||||||
{
|
{
|
||||||
_log.Error("Ignore this.");
|
_log.Error("Ignore this.");
|
||||||
restart = true;
|
//restart = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +101,7 @@ namespace NadekoBot.Services.Music
|
|||||||
if (!written)
|
if (!written)
|
||||||
await Task.Delay(2000, cancelToken);
|
await Task.Delay(2000, cancelToken);
|
||||||
}
|
}
|
||||||
while (!written);
|
while (!written && !cancelToken.IsCancellationRequested);
|
||||||
lock (locker)
|
lock (locker)
|
||||||
if (_outStream.Length > 200_000 || bytesRead == 0)
|
if (_outStream.Length > 200_000 || bytesRead == 0)
|
||||||
if (toReturn.TrySetResult(true))
|
if (toReturn.TrySetResult(true))
|
||||||
|
Loading…
Reference in New Issue
Block a user