diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 422aeb3a..d306b633 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -103,6 +103,7 @@ namespace NadekoBot.Modules }); cgb.CreateCommand(".b").Alias(".ban") + .Parameter("everything",ParameterType.Unparsed) .Description("Bans a mentioned user") .Do(async e => { try { @@ -111,10 +112,11 @@ namespace NadekoBot.Modules await usr.Server.Ban(usr); await e.Send("Banned user " + usr.Name + " Id: " + usr.Id); } - } catch (Exception) { } + } catch (Exception ex) { } }); cgb.CreateCommand(".ub").Alias(".unban") + .Parameter("everything", ParameterType.Unparsed) .Description("Unbans a mentioned user") .Do(async e => { try { @@ -230,7 +232,7 @@ namespace NadekoBot.Modules cgb.CreateCommand(".stats") .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") .Description("Nadeko leaves all servers") @@ -404,7 +406,6 @@ namespace NadekoBot.Modules } }); - }); } diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 39c7fb72..e8f168b8 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -39,6 +39,8 @@ namespace NadekoBot.Modules { Console.WriteLine("Bug in music task run. " + e); } await Task.Delay(200); + + CleanMusicPlayers(); } }); } @@ -57,8 +59,8 @@ namespace NadekoBot.Modules { } } - - public static ConcurrentDictionary musicPlayers = new ConcurrentDictionary(); + + public static ConcurrentDictionary musicPlayers = new ConcurrentDictionary(); public Music() : base() { @@ -76,7 +78,7 @@ namespace NadekoBot.Modules { public override void Install(ModuleManager manager) { var client = NadekoBot.client; - + manager.CreateCommands("!m", cgb => { //queue all more complex commands @@ -137,16 +139,16 @@ namespace NadekoBot.Modules { await e.Send(":musical_note: " + player.SongQueue.Count + " videos currently queued."); await e.Send(string.Join("\n", player.SongQueue.Select(v => v.Title).Take(10))); }); - + cgb.CreateCommand("np") .Alias("playing") .Description("Shows the song currently playing.") - .Do(e => { + .Do(async e => { if (musicPlayers.ContainsKey(e.Server) == false) return; var player = musicPlayers[e.Server]; - e.Send($"Now Playing **{player.CurrentSong.Title}**"); + await e.Send($"Now Playing **{player.CurrentSong.Title}**"); }); - + cgb.CreateCommand("clrbfr") .Alias("clearbuffers") .Description("Clears the music buffer across all servers. **Owner only.**") @@ -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 {