add addtional checks for gateway events logging (#2462)

This commit is contained in:
Misha133
2022-09-14 18:09:12 +03:00
committed by GitHub
parent d4c533aed0
commit b45b1526c0

View File

@@ -746,12 +746,16 @@ namespace Discord.WebSocket
private async Task LogGatewayIntentsWarning() 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); 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); 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);
} }
@@ -765,12 +769,26 @@ namespace Discord.WebSocket
_guildScheduledEventUpdated.HasSubscribers || _guildScheduledEventUpdated.HasSubscribers ||
_guildScheduledEventUserAdd.HasSubscribers; _guildScheduledEventUserAdd.HasSubscribers;
if(_gatewayIntents.HasFlag(GatewayIntents.GuildScheduledEvents) && !hasGuildScheduledEventsSubscribers) 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); 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); 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);
} }
@@ -779,12 +797,21 @@ namespace Discord.WebSocket
_inviteCreatedEvent.HasSubscribers || _inviteCreatedEvent.HasSubscribers ||
_inviteDeletedEvent.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); 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); 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);
} }