mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-02 07:44:27 -05: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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,19 +161,19 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
|
|||||||
public string GetUptimeString(string separator = ", ")
|
public string GetUptimeString(string separator = ", ")
|
||||||
{
|
{
|
||||||
var time = GetUptime();
|
var time = GetUptime();
|
||||||
|
|
||||||
if (time.Days > 0)
|
if (time.Days > 0)
|
||||||
return $"{time.Days}d {time.Hours}h {time.Minutes}m";
|
return $"{time.Days}d {time.Hours}h {time.Minutes}m";
|
||||||
|
|
||||||
if (time.Hours > 0)
|
if (time.Hours > 0)
|
||||||
return $"{time.Hours}h {time.Minutes}m";
|
return $"{time.Hours}h {time.Minutes}m";
|
||||||
|
|
||||||
if (time.Minutes > 0)
|
if (time.Minutes > 0)
|
||||||
return $"{time.Minutes}m {time.Seconds}s";
|
return $"{time.Minutes}m {time.Seconds}s";
|
||||||
|
|
||||||
return $"{time.Seconds}s";
|
return $"{time.Seconds}s";
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetPrivateMemoryMegabytes()
|
public double GetPrivateMemoryMegabytes()
|
||||||
{
|
{
|
||||||
_currentProcess.Refresh();
|
_currentProcess.Refresh();
|
||||||
@@ -202,7 +186,7 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
|
|||||||
public GuildInfo GetGuildInfo(ulong id)
|
public GuildInfo GetGuildInfo(ulong id)
|
||||||
{
|
{
|
||||||
var g = _client.GetGuild(id);
|
var g = _client.GetGuild(id);
|
||||||
|
|
||||||
return new GuildInfo()
|
return new GuildInfo()
|
||||||
{
|
{
|
||||||
Id = g.Id,
|
Id = g.Id,
|
||||||
@@ -219,4 +203,4 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
|
|||||||
MemberCount = g.MemberCount,
|
MemberCount = g.MemberCount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user