Some .stats fixes

This commit is contained in:
Kwoth 2017-01-07 18:32:33 +01:00
parent 0425c52332
commit 21c6c5fc9a
3 changed files with 49 additions and 15 deletions

View File

@ -71,8 +71,8 @@ namespace NadekoBot.Modules.Administration
public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } =
new Dictionary<string, Func<string>> {
{"%servers%", () => NadekoBot.Client.GetGuilds().Count().ToString()},
{"%users%", () => NadekoBot.Client.GetGuilds().Select(s => s.Users.Count).Sum().ToString()},
{"%servers%", () => NadekoBot.Client.GetGuildsCount().ToString()},
{"%users%", () => NadekoBot.Client.GetGuilds().Sum(s => s.Users.Count).ToString()},
{"%playing%", () => {
var cnt = Music.Music.MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null);
if (cnt != 1) return cnt.ToString();

View File

@ -21,14 +21,12 @@ namespace NadekoBot.Services.Impl
public int MessageCounter { get; private set; } = 0;
public int CommandsRan { get; private set; } = 0;
public string Heap =>
#if !GLOBAL_NADEKO
Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString();
#else
"a lot :)";
#endif
public double MessagesPerSecond => MessageCounter / (double)GetUptime().TotalSeconds;
public int TextChannels => client.GetGuilds().SelectMany(g => g.Channels.Where(c => c is ITextChannel)).Count();
public int VoiceChannels => client.GetGuilds().SelectMany(g => g.Channels.Where(c => c is IVoiceChannel)).Count();
private uint _textChannels = 0;
public uint TextChannels => _textChannels;
private uint _voiceChannels = 0;
public uint VoiceChannels => _voiceChannels;
public string OwnerIds => string.Join(", ", NadekoBot.Credentials.OwnerIds);
Timer carbonitexTimer { get; }
@ -44,6 +42,34 @@ namespace NadekoBot.Services.Impl
this.client.Disconnected += _ => Reset();
var guilds = this.client.GetGuilds();
var _textChannels = guilds.Sum(g => g.Channels.Where(cx => cx is ITextChannel).Count());
var _voiceChannels = guilds.Sum(g => g.Channels.Count) - _textChannels;
this.client.ChannelCreated += (c) =>
{
if (c is ITextChannel)
++_textChannels;
else if (c is IVoiceChannel)
++_voiceChannels;
};
this.client.ChannelDestroyed += (c) =>
{
if (c is ITextChannel)
--_textChannels;
else if (c is IVoiceChannel)
--_voiceChannels;
};
this.client.JoinedGuild += (g) =>
{
var tc = g.Channels.Where(cx => cx is ITextChannel).Count();
var vc = g.Channels.Count - tc;
_textChannels += tc;
_voiceChannels += vc;
};
this.carbonitexTimer = new Timer(async (state) =>
{
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.CarbonKey))
@ -54,7 +80,7 @@ namespace NadekoBot.Services.Impl
{
using (var content = new FormUrlEncodedContent(
new Dictionary<string, string> {
{ "servercount", this.client.GetGuilds().Count.ToString() },
{ "servercount", this.client.GetGuildsCount().ToString() },
{ "key", NadekoBot.Credentials.CarbonKey }}))
{
content.Headers.Clear();
@ -76,7 +102,7 @@ Bot Version: [{BotVersion}]
Bot ID: {curUser.Id}
Owner ID(s): {OwnerIds}
Uptime: {GetUptimeString()}
Servers: {client.GetGuilds().Count} | TextChannels: {TextChannels} | VoiceChannels: {VoiceChannels}
Servers: {client.GetGuildsCount()} | TextChannels: {TextChannels} | VoiceChannels: {VoiceChannels}
Commands Ran this session: {CommandsRan}
Messages: {MessageCounter} [{MessagesPerSecond:F2}/sec] Heap: [{Heap} MB]");
}

View File

@ -18,6 +18,7 @@ namespace NadekoBot
public event Action<SocketMessage> MessageReceived = delegate { };
public event Action<SocketGuildUser> UserLeft = delegate { };
public event Action<SocketUser, SocketUser> UserUpdated = delegate { };
public event Action<SocketGuildUser, SocketGuildUser> GuildUserUpdated = delegate { };
public event Action<Optional<SocketMessage>, SocketMessage> MessageUpdated = delegate { };
public event Action<ulong, Optional<SocketMessage>> MessageDeleted = delegate { };
public event Action<SocketUser, SocketGuild> UserBanned = delegate { };
@ -27,6 +28,10 @@ namespace NadekoBot
public event Action<SocketChannel> ChannelCreated = delegate { };
public event Action<SocketChannel> ChannelDestroyed = delegate { };
public event Action<SocketChannel, SocketChannel> ChannelUpdated = delegate { };
public event Action<SocketGuild> JoinedGuild = delegate { };
public event Action<SocketGuild> LeftGuild = delegate { };
public event Action<Exception> Disconnected = delegate { };
private uint _connectedCount = 0;
@ -54,6 +59,7 @@ namespace NadekoBot
};
client.UserLeft += arg1 => { UserLeft(arg1); return Task.CompletedTask; };
client.UserUpdated += (arg1, gu2) => { UserUpdated(arg1, gu2); return Task.CompletedTask; };
client.GuildMemberUpdated += (arg1, arg2) => { GuildUserUpdated(arg1, arg2); return Task.CompletedTask; };
client.MessageUpdated += (arg1, m2) => { MessageUpdated(arg1, m2); return Task.CompletedTask; };
client.MessageDeleted += (arg1, arg2) => { MessageDeleted(arg1, arg2); return Task.CompletedTask; };
client.UserBanned += (arg1, arg2) => { UserBanned(arg1, arg2); return Task.CompletedTask; };
@ -63,6 +69,8 @@ namespace NadekoBot
client.ChannelCreated += arg => { ChannelCreated(arg); return Task.CompletedTask; };
client.ChannelDestroyed += arg => { ChannelDestroyed(arg); return Task.CompletedTask; };
client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
client.JoinedGuild += (arg1) => { JoinedGuild(arg1); return Task.CompletedTask; };
client.LeftGuild += (arg1) => { LeftGuild(arg1); return Task.CompletedTask; };
_log.Info($"Shard #{i} initialized.");
#if GLOBAL_NADEKO
@ -93,8 +101,8 @@ namespace NadekoBot
public SocketSelfUser CurrentUser() =>
Clients[0].CurrentUser;
public IReadOnlyCollection<SocketGuild> GetGuilds() =>
Clients.SelectMany(c => c.Guilds).ToList();
public IEnumerable<SocketGuild> GetGuilds() =>
Clients.SelectMany(c => c.Guilds);
public int GetGuildsCount() =>
Clients.Sum(c => c.Guilds.Count);