mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
fix: Fixed voice and text channel counting
This commit is contained in:
@@ -55,76 +55,60 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
|
|||||||
|
|
||||||
_client.ChannelCreated += c =>
|
_client.ChannelCreated += c =>
|
||||||
{
|
{
|
||||||
_ = Task.Run(() =>
|
if (c is IVoiceChannel)
|
||||||
{
|
Interlocked.Increment(ref voiceChannels);
|
||||||
if (c is ITextChannel)
|
else if (c is ITextChannel)
|
||||||
Interlocked.Increment(ref textChannels);
|
Interlocked.Increment(ref textChannels);
|
||||||
else if (c is IVoiceChannel)
|
|
||||||
Interlocked.Increment(ref voiceChannels);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
_client.ChannelDestroyed += c =>
|
_client.ChannelDestroyed += c =>
|
||||||
{
|
{
|
||||||
_ = Task.Run(() =>
|
if (c is IVoiceChannel)
|
||||||
{
|
Interlocked.Decrement(ref voiceChannels);
|
||||||
if (c is ITextChannel)
|
else if (c is ITextChannel)
|
||||||
Interlocked.Decrement(ref textChannels);
|
Interlocked.Decrement(ref textChannels);
|
||||||
else if (c is IVoiceChannel)
|
|
||||||
Interlocked.Decrement(ref voiceChannels);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
_client.GuildAvailable += g =>
|
_client.GuildAvailable += g =>
|
||||||
{
|
{
|
||||||
_ = Task.Run(() =>
|
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
|
||||||
{
|
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
|
||||||
var tc = g.Channels.Count(cx => cx is ITextChannel);
|
Interlocked.Add(ref textChannels, tc);
|
||||||
var vc = g.Channels.Count - tc;
|
Interlocked.Add(ref voiceChannels, vc);
|
||||||
Interlocked.Add(ref textChannels, tc);
|
|
||||||
Interlocked.Add(ref voiceChannels, vc);
|
|
||||||
});
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
_client.JoinedGuild += g =>
|
_client.JoinedGuild += g =>
|
||||||
{
|
{
|
||||||
_ = Task.Run(() =>
|
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
|
||||||
{
|
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
|
||||||
var tc = g.Channels.Count(cx => cx is ITextChannel);
|
Interlocked.Add(ref textChannels, tc);
|
||||||
var vc = g.Channels.Count - tc;
|
Interlocked.Add(ref voiceChannels, vc);
|
||||||
Interlocked.Add(ref textChannels, tc);
|
|
||||||
Interlocked.Add(ref voiceChannels, vc);
|
|
||||||
});
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
_client.GuildUnavailable += g =>
|
_client.GuildUnavailable += g =>
|
||||||
{
|
{
|
||||||
_ = Task.Run(() =>
|
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
|
||||||
{
|
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
|
||||||
var tc = g.Channels.Count(cx => cx is ITextChannel);
|
Interlocked.Add(ref textChannels, -tc);
|
||||||
var vc = g.Channels.Count - tc;
|
Interlocked.Add(ref voiceChannels, -vc);
|
||||||
Interlocked.Add(ref textChannels, -tc);
|
|
||||||
Interlocked.Add(ref voiceChannels, -vc);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
_client.LeftGuild += g =>
|
_client.LeftGuild += g =>
|
||||||
{
|
{
|
||||||
_ = Task.Run(() =>
|
var tc = g.Channels.Count(cx => cx is ITextChannel and not IVoiceChannel);
|
||||||
{
|
var vc = g.Channels.Count(cx => cx is IVoiceChannel);
|
||||||
var tc = g.Channels.Count(cx => cx is ITextChannel);
|
Interlocked.Add(ref textChannels, -tc);
|
||||||
var vc = g.Channels.Count - tc;
|
Interlocked.Add(ref voiceChannels, -vc);
|
||||||
Interlocked.Add(ref textChannels, -tc);
|
|
||||||
Interlocked.Add(ref voiceChannels, -vc);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
@@ -133,7 +117,7 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
|
|||||||
private void InitializeChannelCount()
|
private void InitializeChannelCount()
|
||||||
{
|
{
|
||||||
var guilds = _client.Guilds;
|
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));
|
voiceChannels = guilds.Sum(static g => g.Channels.Count(static cx => cx is IVoiceChannel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user