cleanup, stats show queued song count. fixed ban
This commit is contained in:
parent
c893736dbb
commit
9284b191ca
@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -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<Server, MusicControls> musicPlayers = new ConcurrentDictionary<Server,MusicControls>();
|
||||
|
||||
public static ConcurrentDictionary<Server, MusicControls> musicPlayers = new ConcurrentDictionary<Server, MusicControls>();
|
||||
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user