feat: add sharding support

This commit is contained in:
sam 2024-08-24 19:02:19 +02:00
parent 8f39d85486
commit c42ca3f888
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
7 changed files with 167 additions and 9 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using Catalogger.Backend.Bot;
using Catalogger.Backend.Cache;
using Humanizer;
using Remora.Discord.API.Abstractions.Rest;
@ -10,7 +11,7 @@ namespace Catalogger.Backend.Services;
public class GuildFetchService(
ILogger logger,
DiscordGatewayClient gatewayClient,
ShardedGatewayClient client,
IDiscordRestGuildAPI guildApi,
IInviteCache inviteCache) : BackgroundService
{
@ -25,7 +26,7 @@ public class GuildFetchService(
if (!_guilds.TryPeek(out var guildId)) continue;
_logger.Debug("Fetching members and invites for guild {GuildId}", guildId);
gatewayClient.SubmitCommand(new RequestGuildMembers(guildId, "", 0));
client.ClientFor(guildId).SubmitCommand(new RequestGuildMembers(guildId, "", 0));
var res = await guildApi.GetGuildInvitesAsync(guildId, stoppingToken);
if (res.Error != null)
{