diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 35bd77e8..ffda1dae 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -23,10 +23,10 @@ namespace NadekoBot.Services.Impl public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString(); public double MessagesPerSecond => MessageCounter / (double)GetUptime().TotalSeconds; - private uint _textChannels = 0; - public uint TextChannels => _textChannels; - private uint _voiceChannels = 0; - public uint VoiceChannels => _voiceChannels; + private int _textChannels = 0; + public int TextChannels => _textChannels; + private int _voiceChannels = 0; + public int VoiceChannels => _voiceChannels; public string OwnerIds => string.Join(", ", NadekoBot.Credentials.OwnerIds); Timer carbonitexTimer { get; } @@ -42,9 +42,12 @@ 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.Connected += () => + { + var guilds = this.client.GetGuilds(); + _textChannels = guilds.Sum(g => g.Channels.Where(cx => cx is ITextChannel).Count()); + _voiceChannels = guilds.Sum(g => g.Channels.Count) - _textChannels; + }; this.client.ChannelCreated += (c) => { @@ -70,6 +73,14 @@ namespace NadekoBot.Services.Impl _voiceChannels += vc; }; + this.client.LeftGuild += (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)) diff --git a/src/NadekoBot/ShardedDiscordClient.cs b/src/NadekoBot/ShardedDiscordClient.cs index e7f2604c..af6fc045 100644 --- a/src/NadekoBot/ShardedDiscordClient.cs +++ b/src/NadekoBot/ShardedDiscordClient.cs @@ -33,6 +33,7 @@ namespace NadekoBot public event Action LeftGuild = delegate { }; public event Action Disconnected = delegate { }; + public event Action Connected = delegate { }; private uint _connectedCount = 0; private uint _downloadedCount = 0; @@ -145,6 +146,7 @@ namespace NadekoBot } } } + Connected(); } internal Task DownloadAllUsersAsync() =>