Doesn't leave when finished playing. Totaly stable, tested and proven /sarcasm
This commit is contained in:
parent
f9a1ca0c50
commit
9506dbb72c
@ -28,7 +28,8 @@ namespace NadekoBot.Classes.Music {
|
|||||||
|
|
||||||
public MusicControls() {
|
public MusicControls() {
|
||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
while (!Stopped) {
|
while (true) {
|
||||||
|
if (!Stopped) {
|
||||||
if (CurrentSong == null) {
|
if (CurrentSong == null) {
|
||||||
if (SongQueue.Count > 0)
|
if (SongQueue.Count > 0)
|
||||||
await LoadNextSong();
|
await LoadNextSong();
|
||||||
@ -38,11 +39,19 @@ namespace NadekoBot.Classes.Music {
|
|||||||
NextSong = false;
|
NextSong = false;
|
||||||
await LoadNextSong();
|
await LoadNextSong();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (VoiceClient == null)
|
||||||
|
break;
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void AddSong(StreamRequest streamRequest) {
|
||||||
|
Stopped = false;
|
||||||
|
this.SongQueue.Add(streamRequest);
|
||||||
|
}
|
||||||
|
|
||||||
public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
|
public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
|
||||||
if (voiceChannel == null)
|
if (voiceChannel == null)
|
||||||
throw new ArgumentNullException(nameof(voiceChannel));
|
throw new ArgumentNullException(nameof(voiceChannel));
|
||||||
@ -60,8 +69,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
SongQueue.RemoveAt(0);
|
SongQueue.RemoveAt(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VoiceClient?.Disconnect();
|
Stop();
|
||||||
VoiceClient = null;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,17 +89,19 @@ namespace NadekoBot.Classes.Music {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Stop() {
|
internal void Stop(bool leave = false) {
|
||||||
Stopped = true;
|
Stopped = true;
|
||||||
SongQueue.Clear();
|
SongQueue.Clear();
|
||||||
CurrentSong?.Stop();
|
CurrentSong?.Stop();
|
||||||
CurrentSong = null;
|
CurrentSong = null;
|
||||||
|
if (leave) {
|
||||||
VoiceClient?.Disconnect();
|
VoiceClient?.Disconnect();
|
||||||
VoiceClient = null;
|
VoiceClient = null;
|
||||||
|
|
||||||
MusicControls throwAwayValue;
|
MusicControls throwAwayValue;
|
||||||
MusicModule.musicPlayers.TryRemove(_e.Server, out throwAwayValue);
|
MusicModule.musicPlayers.TryRemove(_e.Server, out throwAwayValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int SetVolume(int value) {
|
public int SetVolume(int value) {
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
|
@ -49,7 +49,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
this.Server = e.Server;
|
this.Server = e.Server;
|
||||||
this.Query = query;
|
this.Query = query;
|
||||||
this.RadioLink = radio;
|
this.RadioLink = radio;
|
||||||
mc.SongQueue.Add(this);
|
mc.AddSong(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Resolve() {
|
public async Task Resolve() {
|
||||||
|
@ -16,7 +16,7 @@ namespace NadekoBot.Commands {
|
|||||||
{"%servers%", ()=> NadekoBot.client.Servers.Count().ToString() },
|
{"%servers%", ()=> NadekoBot.client.Servers.Count().ToString() },
|
||||||
{"%users%", () => NadekoBot.client.Servers.SelectMany(s=>s.Users).Count().ToString() },
|
{"%users%", () => NadekoBot.client.Servers.SelectMany(s=>s.Users).Count().ToString() },
|
||||||
{"%playing%", () => {
|
{"%playing%", () => {
|
||||||
var cnt = Modules.Music.musicPlayers.Count;
|
var cnt = Modules.Music.musicPlayers.Where(kvp => kvp.Value.CurrentSong != null).Count();
|
||||||
if(cnt == 1) {
|
if(cnt == 1) {
|
||||||
try {
|
try {
|
||||||
var mp = Modules.Music.musicPlayers.FirstOrDefault();
|
var mp = Modules.Music.musicPlayers.FirstOrDefault();
|
||||||
|
@ -49,7 +49,7 @@ namespace NadekoBot.Modules {
|
|||||||
.Description("Completely stops the music, unbinds the bot from the channel, and cleans up files.")
|
.Description("Completely stops the music, unbinds the bot from the channel, and cleans up files.")
|
||||||
.Do(e => {
|
.Do(e => {
|
||||||
if (musicPlayers.ContainsKey(e.Server) == false) return;
|
if (musicPlayers.ContainsKey(e.Server) == false) return;
|
||||||
musicPlayers[e.Server].Stop();
|
musicPlayers[e.Server].Stop(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("p")
|
cgb.CreateCommand("p")
|
||||||
|
Loading…
Reference in New Issue
Block a user