From 21d029c27f942f5a65fb8cc67bdaea1a84873717 Mon Sep 17 00:00:00 2001 From: Misha133 Date: Sun, 11 Sep 2022 22:35:43 +0300 Subject: [PATCH] add addtional checks for gateway events logging --- .../DiscordSocketClient.cs | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 670ed4567..c302daa69 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -743,31 +743,49 @@ namespace Discord.WebSocket private async Task LogGatewayIntentsWarning() { - if(_gatewayIntents.HasFlag(GatewayIntents.GuildPresences) && !_presenceUpdated.HasSubscribers) + if (_gatewayIntents.HasFlag(GatewayIntents.GuildPresences) && + (_shardedClient is null && !_presenceUpdated.HasSubscribers || + (_shardedClient is not null && !_shardedClient._presenceUpdated.HasSubscribers))) { await _gatewayLogger.WarningAsync("You're using the GuildPresences intent without listening to the PresenceUpdate event, consider removing the intent from your config.").ConfigureAwait(false); } - if(!_gatewayIntents.HasFlag(GatewayIntents.GuildPresences) && _presenceUpdated.HasSubscribers) + if(!_gatewayIntents.HasFlag(GatewayIntents.GuildPresences) && + ((_shardedClient is null && _presenceUpdated.HasSubscribers) || + (_shardedClient is not null && _shardedClient._presenceUpdated.HasSubscribers))) { await _gatewayLogger.WarningAsync("You're using the PresenceUpdate event without specifying the GuildPresences intent. Discord wont send this event to your client without the intent set in your config.").ConfigureAwait(false); } bool hasGuildScheduledEventsSubscribers = _guildScheduledEventCancelled.HasSubscribers || - _guildScheduledEventUserRemove.HasSubscribers || - _guildScheduledEventCompleted.HasSubscribers || - _guildScheduledEventCreated.HasSubscribers || - _guildScheduledEventStarted.HasSubscribers || - _guildScheduledEventUpdated.HasSubscribers || - _guildScheduledEventUserAdd.HasSubscribers; - - if(_gatewayIntents.HasFlag(GatewayIntents.GuildScheduledEvents) && !hasGuildScheduledEventsSubscribers) + _guildScheduledEventUserRemove.HasSubscribers || + _guildScheduledEventCompleted.HasSubscribers || + _guildScheduledEventCreated.HasSubscribers || + _guildScheduledEventStarted.HasSubscribers || + _guildScheduledEventUpdated.HasSubscribers || + _guildScheduledEventUserAdd.HasSubscribers; + + bool shardedClientHasGuildScheduledEventsSubscribers = + _shardedClient is not null && + (_shardedClient._guildScheduledEventCancelled.HasSubscribers || + _shardedClient._guildScheduledEventUserRemove.HasSubscribers || + _shardedClient._guildScheduledEventCompleted.HasSubscribers || + _shardedClient._guildScheduledEventCreated.HasSubscribers || + _shardedClient._guildScheduledEventStarted.HasSubscribers || + _shardedClient._guildScheduledEventUpdated.HasSubscribers || + _shardedClient._guildScheduledEventUserAdd.HasSubscribers); + + if (_gatewayIntents.HasFlag(GatewayIntents.GuildScheduledEvents) && + ((_shardedClient is null && !hasGuildScheduledEventsSubscribers) || + (_shardedClient is not null && !shardedClientHasGuildScheduledEventsSubscribers))) { await _gatewayLogger.WarningAsync("You're using the GuildScheduledEvents gateway intent without listening to any events related to that intent, consider removing the intent from your config.").ConfigureAwait(false); } - if(!_gatewayIntents.HasFlag(GatewayIntents.GuildScheduledEvents) && hasGuildScheduledEventsSubscribers) + if(!_gatewayIntents.HasFlag(GatewayIntents.GuildScheduledEvents) && + ((_shardedClient is null && hasGuildScheduledEventsSubscribers) || + (_shardedClient is not null && shardedClientHasGuildScheduledEventsSubscribers))) { await _gatewayLogger.WarningAsync("You're using events related to the GuildScheduledEvents gateway intent without specifying the intent. Discord wont send this event to your client without the intent set in your config.").ConfigureAwait(false); } @@ -776,12 +794,21 @@ namespace Discord.WebSocket _inviteCreatedEvent.HasSubscribers || _inviteDeletedEvent.HasSubscribers; - if (_gatewayIntents.HasFlag(GatewayIntents.GuildInvites) && !hasInviteEventSubscribers) + bool shardedClientHasInviteEventSubscribers = + _shardedClient is not null && + (_shardedClient._inviteCreatedEvent.HasSubscribers || + _shardedClient._inviteDeletedEvent.HasSubscribers); + + if (_gatewayIntents.HasFlag(GatewayIntents.GuildInvites) && + ((_shardedClient is null && !hasInviteEventSubscribers) || + (_shardedClient is not null && !shardedClientHasInviteEventSubscribers))) { await _gatewayLogger.WarningAsync("You're using the GuildInvites gateway intent without listening to any events related to that intent, consider removing the intent from your config.").ConfigureAwait(false); } - if (!_gatewayIntents.HasFlag(GatewayIntents.GuildInvites) && hasInviteEventSubscribers) + if (!_gatewayIntents.HasFlag(GatewayIntents.GuildInvites) && + ((_shardedClient is null && hasInviteEventSubscribers) || + (_shardedClient is not null && shardedClientHasInviteEventSubscribers))) { await _gatewayLogger.WarningAsync("You're using events related to the GuildInvites gateway intent without specifying the intent. Discord wont send this event to your client without the intent set in your config.").ConfigureAwait(false); }