cleanup, stats show queued song count. fixed ban

This commit is contained in:
Master Kwoth 2016-01-23 19:42:11 +01:00
parent c893736dbb
commit 9284b191ca
2 changed files with 35 additions and 10 deletions

View File

@ -103,6 +103,7 @@ namespace NadekoBot.Modules
}); });
cgb.CreateCommand(".b").Alias(".ban") cgb.CreateCommand(".b").Alias(".ban")
.Parameter("everything",ParameterType.Unparsed)
.Description("Bans a mentioned user") .Description("Bans a mentioned user")
.Do(async e => { .Do(async e => {
try { try {
@ -111,10 +112,11 @@ namespace NadekoBot.Modules
await usr.Server.Ban(usr); await usr.Server.Ban(usr);
await e.Send("Banned user " + usr.Name + " Id: " + usr.Id); await e.Send("Banned user " + usr.Name + " Id: " + usr.Id);
} }
} catch (Exception) { } } catch (Exception ex) { }
}); });
cgb.CreateCommand(".ub").Alias(".unban") cgb.CreateCommand(".ub").Alias(".unban")
.Parameter("everything", ParameterType.Unparsed)
.Description("Unbans a mentioned user") .Description("Unbans a mentioned user")
.Do(async e => { .Do(async e => {
try { try {
@ -230,7 +232,7 @@ namespace NadekoBot.Modules
cgb.CreateCommand(".stats") cgb.CreateCommand(".stats")
.Description("Shows some basic stats for nadeko") .Description("Shows some basic stats for nadeko")
.Do(async e => await e.Send("```" + NadekoBot.GetStats() + "```")); .Do(async e => await e.Send("```" + NadekoBot.GetStats() + "\n" + Music.GetMusicStats() + "```"));
cgb.CreateCommand(".leaveall") cgb.CreateCommand(".leaveall")
.Description("Nadeko leaves all servers") .Description("Nadeko leaves all servers")
@ -404,7 +406,6 @@ namespace NadekoBot.Modules
} }
}); });
}); });
} }

View File

@ -39,6 +39,8 @@ namespace NadekoBot.Modules {
Console.WriteLine("Bug in music task run. " + e); Console.WriteLine("Bug in music task run. " + e);
} }
await Task.Delay(200); await Task.Delay(200);
CleanMusicPlayers();
} }
}); });
} }
@ -141,10 +143,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("np") cgb.CreateCommand("np")
.Alias("playing") .Alias("playing")
.Description("Shows the song currently playing.") .Description("Shows the song currently playing.")
.Do(e => { .Do(async e => {
if (musicPlayers.ContainsKey(e.Server) == false) return; if (musicPlayers.ContainsKey(e.Server) == false) return;
var player = musicPlayers[e.Server]; var player = musicPlayers[e.Server];
e.Send($"Now Playing **{player.CurrentSong.Title}**"); await e.Send($"Now Playing **{player.CurrentSong.Title}**");
}); });
cgb.CreateCommand("clrbfr") cgb.CreateCommand("clrbfr")
@ -170,6 +172,28 @@ namespace NadekoBot.Modules {
}); });
}); });
} }
internal static void CleanMusicPlayers() {
foreach (var mp in musicPlayers
.Where(kvp => kvp.Value.CurrentSong == null
&& kvp.Value.SongQueue.Count == 0)) {
var val = mp.Value;
musicPlayers.TryRemove(mp.Key, out val);
}
}
internal static string GetMusicStats() {
var servers = 0;
var queued = 0;
musicPlayers.ForEach(kvp => {
var mp = kvp.Value;
if(mp.SongQueue.Count > 0 || mp.CurrentSong != null)
queued += mp.SongQueue.Count + 1;
servers++;
});
return $"Playing {queued} songs across {servers} servers.";
}
} }
enum StreamTaskState { enum StreamTaskState {