Skip to content

Commit

Permalink
add addtional checks for gateway events logging (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 authored Sep 14, 2022
1 parent d4c533a commit b45b152
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,31 +746,49 @@ await ApiClient.SendPresenceUpdateAsync(

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);
}
Expand All @@ -779,12 +797,21 @@ private async Task LogGatewayIntentsWarning()
_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);
}
Expand Down

0 comments on commit b45b152

Please sign in to comment.