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;
|
||||
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;
|
||||
public StreamState State => musicStreamer?.State ?? privateState;
|
||||
@ -74,7 +74,8 @@ namespace NadekoBot.Classes.Music {
|
||||
Provider = "SoundCloud";
|
||||
uri = svideo.StreamLink;
|
||||
Console.WriteLine(uri);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
if (OnResolving != null)
|
||||
OnResolving();
|
||||
@ -89,11 +90,12 @@ namespace NadekoBot.Classes.Music {
|
||||
if (video == null) // do something with this error
|
||||
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";
|
||||
uri = video.Uri;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
privateState = StreamState.Completed;
|
||||
if (OnResolvingFailed != null)
|
||||
OnResolvingFailed(ex.Message);
|
||||
@ -134,10 +136,12 @@ namespace NadekoBot.Classes.Music {
|
||||
}
|
||||
}
|
||||
await musicStreamer.StartPlayback();
|
||||
} catch (TimeoutException) {
|
||||
}
|
||||
catch (TimeoutException) {
|
||||
Console.WriteLine("Resolving timed out.");
|
||||
privateState = StreamState.Completed;
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Console.WriteLine("Error in start playback." + ex.Message);
|
||||
privateState = StreamState.Completed;
|
||||
}
|
||||
@ -192,7 +196,8 @@ namespace NadekoBot.Classes.Music {
|
||||
try {
|
||||
p.CancelOutputRead();
|
||||
p.Close();
|
||||
} catch { }
|
||||
}
|
||||
catch { }
|
||||
Console.WriteLine("Buffering canceled, stream is completed.");
|
||||
return;
|
||||
}
|
||||
@ -221,15 +226,18 @@ namespace NadekoBot.Classes.Music {
|
||||
try {
|
||||
p.CancelOutputRead();
|
||||
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;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
++attempt;
|
||||
await Task.Delay(20);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
attempt = 0;
|
||||
await buffer.WriteAsync(buf, 0, read);
|
||||
}
|
||||
@ -254,13 +262,14 @@ namespace NadekoBot.Classes.Music {
|
||||
await Task.Delay(waitPerAttempt);
|
||||
}
|
||||
if (prebufferingComplete) {
|
||||
Console.WriteLine($"Prebuffering finished in {bufferAttempts*500}");
|
||||
Console.WriteLine($"Prebuffering finished in {bufferAttempts * 500}");
|
||||
}
|
||||
// prebuffering wait stuff end
|
||||
|
||||
if (buffer.Length > 0) {
|
||||
Console.WriteLine("Prebuffering complete.");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey.");
|
||||
}
|
||||
|
||||
@ -283,11 +292,13 @@ namespace NadekoBot.Classes.Music {
|
||||
if (attempt == 4) {
|
||||
Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]");
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
++attempt;
|
||||
await Task.Delay(15);
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
attempt = 0;
|
||||
|
||||
if (State == StreamState.Completed) {
|
||||
|
@ -52,7 +52,10 @@ namespace NadekoBot.Commands {
|
||||
|
||||
if (controls.ByePM) {
|
||||
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 {
|
||||
if (channel == null) return;
|
||||
Greeted++;
|
||||
|
@ -207,6 +207,23 @@ namespace NadekoBot.Modules {
|
||||
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")
|
||||
.Description("Writes some music data to console. **BOT OWNER ONLY**")
|
||||
.Do(e => {
|
||||
@ -229,7 +246,7 @@ namespace NadekoBot.Modules {
|
||||
await e.Send("Failed to create a music player for this server.");
|
||||
return;
|
||||
}
|
||||
if (query == null || query.Length < 4)
|
||||
if (query == null || query.Length < 3)
|
||||
return;
|
||||
|
||||
var player = musicPlayers[e.Server];
|
||||
|
Loading…
Reference in New Issue
Block a user