1
Fork 0
mirror of https://gitlab.com/Kwoth/nadekobot.git synced 2024-10-02 20:13:13 +00:00

fix: Fixed voice and text channel counting

This commit is contained in:
Kwoth 2024-09-05 06:04:47 +00:00
parent e85e7c49cb
commit c36ab34c4f

View file

@ -55,76 +55,60 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
_client.ChannelCreated += c =>
{
_ = Task.Run(() =>
{
if (c is ITextChannel)
Interlocked.Increment(ref textChannels);
else if (c is IVoiceChannel)
if (c is IVoiceChannel)
Interlocked.Increment(ref voiceChannels);
});
else if (c is ITextChannel)
Interlocked.Increment(ref textChannels);
return Task.CompletedTask;
};
_client.ChannelDestroyed += c =>
{
_ = Task.Run(() =>
{
if (c is ITextChannel)
Interlocked.Decrement(ref textChannels);
else if (c is IVoiceChannel)
if (c is IVoiceChannel)
Interlocked.Decrement(ref voiceChannels);
});
else if (c is ITextChannel)
Interlocked.Decrement(ref textChannels);
return Task.CompletedTask;
};
_client.GuildAvailable += g =>
{
_ = Task.Run(() =>
{
var tc = g.Channels.Count(cx => cx is ITextChannel);
var vc = g.Channels.Count - tc;
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
Interlocked.Add(ref textChannels, tc);
Interlocked.Add(ref voiceChannels, vc);
});
return Task.CompletedTask;
};
_client.JoinedGuild += g =>
{
_ = Task.Run(() =>
{
var tc = g.Channels.Count(cx => cx is ITextChannel);
var vc = g.Channels.Count - tc;
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
Interlocked.Add(ref textChannels, tc);
Interlocked.Add(ref voiceChannels, vc);
});
return Task.CompletedTask;
};
_client.GuildUnavailable += g =>
{
_ = Task.Run(() =>
{
var tc = g.Channels.Count(cx => cx is ITextChannel);
var vc = g.Channels.Count - tc;
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
Interlocked.Add(ref textChannels, -tc);
Interlocked.Add(ref voiceChannels, -vc);
});
return Task.CompletedTask;
};
_client.LeftGuild += g =>
{
_ = Task.Run(() =>
{
var tc = g.Channels.Count(cx => cx is ITextChannel);
var vc = g.Channels.Count - tc;
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
Interlocked.Add(ref textChannels, -tc);
Interlocked.Add(ref voiceChannels, -vc);
});
return Task.CompletedTask;
};
@ -133,7 +117,7 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
private void InitializeChannelCount()
{
var guilds = _client.Guilds;
textChannels = guilds.Sum(static g => g.Channels.Count(static cx => cx is ITextChannel));
textChannels = guilds.Sum(static g => g.Channels.Count(static cx => cx is ITextChannel and not IVoiceChannel));
voiceChannels = guilds.Sum(static g => g.Channels.Count(static cx => cx is IVoiceChannel));
}