diff --git a/PluralKit.Bot/Bot.cs b/PluralKit.Bot/Bot.cs index ed5fd231..3731bc84 100644 --- a/PluralKit.Bot/Bot.cs +++ b/PluralKit.Bot/Bot.cs @@ -151,11 +151,6 @@ namespace PluralKit.Bot _client.MessageReceived += (msg) => { - // _client.CurrentUser will be null if we've connected *some* shards but not shard #0 yet - // This will cause an error in WebhookCacheService so we just workaround and don't process any messages - // until we properly connect. TODO: can we do this without chucking away a bunch of messages? - if (_client.CurrentUser == null) return Task.CompletedTask; - return HandleEvent(s => s.AddMessageBreadcrumb(msg), eh => eh.HandleMessage(msg)); }; _client.ReactionAdded += (msg, channel, reaction) => HandleEvent(s => s.AddReactionAddedBreadcrumb(msg, channel, reaction), eh => eh.HandleReactionAdded(msg, channel, reaction)); diff --git a/PluralKit.Bot/Services/WebhookCacheService.cs b/PluralKit.Bot/Services/WebhookCacheService.cs index cf107d56..06791953 100644 --- a/PluralKit.Bot/Services/WebhookCacheService.cs +++ b/PluralKit.Bot/Services/WebhookCacheService.cs @@ -5,6 +5,8 @@ using System.Net.Http; using System.Threading.Tasks; using Discord; using Discord.Webhook; +using Discord.WebSocket; + using Serilog; namespace PluralKit.Bot @@ -13,21 +15,21 @@ namespace PluralKit.Bot { public static readonly string WebhookName = "PluralKit Proxy Webhook"; - private IDiscordClient _client; + private DiscordShardedClient _client; private ConcurrentDictionary>> _webhooks; private ILogger _logger; public WebhookCacheService(IDiscordClient client, ILogger logger) { - _client = client; + _client = client as DiscordShardedClient; _logger = logger.ForContext(); _webhooks = new ConcurrentDictionary>>(); } public async Task GetWebhook(ulong channelId) { - var channel = await _client.GetChannelAsync(channelId) as ITextChannel; + var channel = _client.GetChannel(channelId) as ITextChannel; if (channel == null) return null; return await GetWebhook(channel); } @@ -83,7 +85,7 @@ namespace PluralKit.Bot return channel.CreateWebhookAsync(WebhookName); } - private bool IsWebhookMine(IWebhook arg) => arg.Creator.Id == _client.CurrentUser.Id && arg.Name == WebhookName; + private bool IsWebhookMine(IWebhook arg) => arg.Creator.Id == _client.GetShardFor(arg.Guild).CurrentUser.Id && arg.Name == WebhookName; public int CacheSize => _webhooks.Count; }