music fixes, added !m rm # command
This commit is contained in:
parent
5901e25c42
commit
260f57372a
@ -31,7 +31,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
public string Title { get; internal set; } = String.Empty;
|
public string Title { get; internal set; } = String.Empty;
|
||||||
private string Provider { get; set; }
|
private string Provider { get; set; }
|
||||||
|
|
||||||
public string FullPrettyName => $"**【 {Title.TrimTo(55)} 】**`{Provider}`";
|
public string FullPrettyName => $"**【 {Title.TrimTo(55)} 】**`{(Provider == null ? "-" : Provider)}`";
|
||||||
|
|
||||||
private MusicStreamer musicStreamer = null;
|
private MusicStreamer musicStreamer = null;
|
||||||
public StreamState State => musicStreamer?.State ?? privateState;
|
public StreamState State => musicStreamer?.State ?? privateState;
|
||||||
@ -74,7 +74,8 @@ namespace NadekoBot.Classes.Music {
|
|||||||
Provider = "SoundCloud";
|
Provider = "SoundCloud";
|
||||||
uri = svideo.StreamLink;
|
uri = svideo.StreamLink;
|
||||||
Console.WriteLine(uri);
|
Console.WriteLine(uri);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
if (OnResolving != null)
|
if (OnResolving != null)
|
||||||
OnResolving();
|
OnResolving();
|
||||||
@ -89,11 +90,12 @@ namespace NadekoBot.Classes.Music {
|
|||||||
if (video == null) // do something with this error
|
if (video == null) // do something with this error
|
||||||
throw new Exception("Could not load any video elements based on the query.");
|
throw new Exception("Could not load any video elements based on the query.");
|
||||||
|
|
||||||
Title = video.Title.Substring(0,video.Title.Length-10); // removing trailing "- You Tube"
|
Title = video.Title.Substring(0, video.Title.Length - 10); // removing trailing "- You Tube"
|
||||||
Provider = "YouTube";
|
Provider = "YouTube";
|
||||||
uri = video.Uri;
|
uri = video.Uri;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
privateState = StreamState.Completed;
|
privateState = StreamState.Completed;
|
||||||
if (OnResolvingFailed != null)
|
if (OnResolvingFailed != null)
|
||||||
OnResolvingFailed(ex.Message);
|
OnResolvingFailed(ex.Message);
|
||||||
@ -134,10 +136,12 @@ namespace NadekoBot.Classes.Music {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await musicStreamer.StartPlayback();
|
await musicStreamer.StartPlayback();
|
||||||
} catch (TimeoutException) {
|
}
|
||||||
|
catch (TimeoutException) {
|
||||||
Console.WriteLine("Resolving timed out.");
|
Console.WriteLine("Resolving timed out.");
|
||||||
privateState = StreamState.Completed;
|
privateState = StreamState.Completed;
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
Console.WriteLine("Error in start playback." + ex.Message);
|
Console.WriteLine("Error in start playback." + ex.Message);
|
||||||
privateState = StreamState.Completed;
|
privateState = StreamState.Completed;
|
||||||
}
|
}
|
||||||
@ -169,7 +173,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
$"Server: {parent.Server.Name}\n" +
|
$"Server: {parent.Server.Name}\n" +
|
||||||
$"Length:{buffer.Length * 1.0f / 1.MB()}MB Status: {State}\n" +
|
$"Length:{buffer.Length * 1.0f / 1.MB()}MB Status: {State}\n" +
|
||||||
"--------------------------------\n";
|
"--------------------------------\n";
|
||||||
|
|
||||||
private async Task BufferSong() {
|
private async Task BufferSong() {
|
||||||
//start feeding the buffer
|
//start feeding the buffer
|
||||||
var p = Process.Start(new ProcessStartInfo {
|
var p = Process.Start(new ProcessStartInfo {
|
||||||
@ -192,7 +196,8 @@ namespace NadekoBot.Classes.Music {
|
|||||||
try {
|
try {
|
||||||
p.CancelOutputRead();
|
p.CancelOutputRead();
|
||||||
p.Close();
|
p.Close();
|
||||||
} catch { }
|
}
|
||||||
|
catch { }
|
||||||
Console.WriteLine("Buffering canceled, stream is completed.");
|
Console.WriteLine("Buffering canceled, stream is completed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -221,15 +226,18 @@ namespace NadekoBot.Classes.Music {
|
|||||||
try {
|
try {
|
||||||
p.CancelOutputRead();
|
p.CancelOutputRead();
|
||||||
p.Close();
|
p.Close();
|
||||||
} catch { }
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length/1.MB()}MB length");
|
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length");
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
++attempt;
|
++attempt;
|
||||||
await Task.Delay(20);
|
await Task.Delay(20);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
attempt = 0;
|
attempt = 0;
|
||||||
await buffer.WriteAsync(buf, 0, read);
|
await buffer.WriteAsync(buf, 0, read);
|
||||||
}
|
}
|
||||||
@ -254,16 +262,17 @@ namespace NadekoBot.Classes.Music {
|
|||||||
await Task.Delay(waitPerAttempt);
|
await Task.Delay(waitPerAttempt);
|
||||||
}
|
}
|
||||||
if (prebufferingComplete) {
|
if (prebufferingComplete) {
|
||||||
Console.WriteLine($"Prebuffering finished in {bufferAttempts*500}");
|
Console.WriteLine($"Prebuffering finished in {bufferAttempts * 500}");
|
||||||
}
|
}
|
||||||
// prebuffering wait stuff end
|
// prebuffering wait stuff end
|
||||||
|
|
||||||
if (buffer.Length > 0) {
|
if (buffer.Length > 0) {
|
||||||
Console.WriteLine("Prebuffering complete.");
|
Console.WriteLine("Prebuffering complete.");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey.");
|
Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int blockSize = 1920 * NadekoBot.client.Services.Get<AudioService>().Config.Channels;
|
int blockSize = 1920 * NadekoBot.client.Services.Get<AudioService>().Config.Channels;
|
||||||
byte[] voiceBuffer = new byte[blockSize];
|
byte[] voiceBuffer = new byte[blockSize];
|
||||||
|
|
||||||
@ -274,7 +283,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
while (!IsCanceled) {
|
while (!IsCanceled) {
|
||||||
int readCount = 0;
|
int readCount = 0;
|
||||||
//adjust volume
|
//adjust volume
|
||||||
|
|
||||||
lock (_bufferLock) {
|
lock (_bufferLock) {
|
||||||
readCount = buffer.Read(voiceBuffer, 0, voiceBuffer.Length);
|
readCount = buffer.Read(voiceBuffer, 0, voiceBuffer.Length);
|
||||||
}
|
}
|
||||||
@ -283,11 +292,13 @@ namespace NadekoBot.Classes.Music {
|
|||||||
if (attempt == 4) {
|
if (attempt == 4) {
|
||||||
Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]");
|
Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]");
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
++attempt;
|
++attempt;
|
||||||
await Task.Delay(15);
|
await Task.Delay(15);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
attempt = 0;
|
attempt = 0;
|
||||||
|
|
||||||
if (State == StreamState.Completed) {
|
if (State == StreamState.Completed) {
|
||||||
|
@ -52,7 +52,10 @@ namespace NadekoBot.Commands {
|
|||||||
|
|
||||||
if (controls.ByePM) {
|
if (controls.ByePM) {
|
||||||
Greeted++;
|
Greeted++;
|
||||||
await e.User.SendMessage($"`Farewell Message From {e.Server.Name}`\n" + msg);
|
try {
|
||||||
|
await e.User.SendMessage($"`Farewell Message From {e.Server?.Name}`\n" + msg);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
} else {
|
} else {
|
||||||
if (channel == null) return;
|
if (channel == null) return;
|
||||||
Greeted++;
|
Greeted++;
|
||||||
|
@ -207,6 +207,23 @@ namespace NadekoBot.Modules {
|
|||||||
mc.VoiceClient = await mc.VoiceChannel.JoinAudio();
|
mc.VoiceClient = await mc.VoiceChannel.JoinAudio();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand("rm")
|
||||||
|
.Description("Removes a song by a # from the queue")
|
||||||
|
.Parameter("num",ParameterType.Required)
|
||||||
|
.Do(async e => {
|
||||||
|
var arg = e.GetArg("num");
|
||||||
|
int num;
|
||||||
|
MusicControls mc;
|
||||||
|
if (!musicPlayers.TryGetValue(e.Server, out mc) || !int.TryParse(arg, out num)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (num <= 0 || num > mc.SongQueue.Count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mc.SongQueue.RemoveAt(num - 1);
|
||||||
|
await e.Send($"🎵Song at position `{num}` has been removed.");
|
||||||
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("debug")
|
cgb.CreateCommand("debug")
|
||||||
.Description("Writes some music data to console. **BOT OWNER ONLY**")
|
.Description("Writes some music data to console. **BOT OWNER ONLY**")
|
||||||
.Do(e => {
|
.Do(e => {
|
||||||
@ -229,7 +246,7 @@ namespace NadekoBot.Modules {
|
|||||||
await e.Send("Failed to create a music player for this server.");
|
await e.Send("Failed to create a music player for this server.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (query == null || query.Length < 4)
|
if (query == null || query.Length < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var player = musicPlayers[e.Server];
|
var player = musicPlayers[e.Server];
|
||||||
|
Loading…
Reference in New Issue
Block a user