Fixed voice and text channel counting

Updated changelog
This commit is contained in:
Toastie (DCS Team) 2024-09-06 17:11:01 +12:00
parent 742d98a4c1
commit d58f1393ec
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
2 changed files with 32 additions and 43 deletions

View file

@ -6,6 +6,9 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
### Added
- Added `.leaveunkeptservers` which will make the bot leave all servers on all shards whose owners didn't run `.keep` command.
- This is a dangerous and irreversible command, don't use it. Meant for use on the public bot.
### Changed
- `.quote` commands cleaned up and improved
@ -21,6 +24,8 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
- Fixed `.xpcurrew` breaking xp gain if user gains 0 xp from being in a voice channel
- Fixed a bug in `.gatari` command
- Fixed some waifu related strings
- Fixed `.quoteshow` and `.quoteid` commands
## [5.1.7] - 09.08.2024

View file

@ -55,76 +55,60 @@ public sealed class StatsService : IStatsService, IReadyExecutor, IEService
_client.ChannelCreated += c =>
{
_ = Task.Run(() =>
{
if (c is ITextChannel)
Interlocked.Increment(ref textChannels);
else if (c is IVoiceChannel)
Interlocked.Increment(ref voiceChannels);
});
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)
Interlocked.Decrement(ref voiceChannels);
});
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;
Interlocked.Add(ref textChannels, tc);
Interlocked.Add(ref voiceChannels, vc);
});
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;
Interlocked.Add(ref textChannels, tc);
Interlocked.Add(ref voiceChannels, vc);
});
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;
Interlocked.Add(ref textChannels, -tc);
Interlocked.Add(ref voiceChannels, -vc);
});
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;
Interlocked.Add(ref textChannels, -tc);
Interlocked.Add(ref voiceChannels, -vc);
});
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, IEService
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));
}