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();
} }
}); });
} }
@ -57,8 +59,8 @@ namespace NadekoBot.Modules {
} }
} }
public static ConcurrentDictionary<Server, MusicControls> musicPlayers = new ConcurrentDictionary<Server,MusicControls>(); public static ConcurrentDictionary<Server, MusicControls> musicPlayers = new ConcurrentDictionary<Server, MusicControls>();
public Music() : base() { public Music() : base() {
@ -76,7 +78,7 @@ namespace NadekoBot.Modules {
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager) {
var client = NadekoBot.client; var client = NadekoBot.client;
manager.CreateCommands("!m", cgb => { manager.CreateCommands("!m", cgb => {
//queue all more complex commands //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(":musical_note: " + player.SongQueue.Count + " videos currently queued.");
await e.Send(string.Join("\n", player.SongQueue.Select(v => v.Title).Take(10))); await e.Send(string.Join("\n", player.SongQueue.Select(v => v.Title).Take(10)));
}); });
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")
.Alias("clearbuffers") .Alias("clearbuffers")
.Description("Clears the music buffer across all servers. **Owner only.**") .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 { enum StreamTaskState {