public Task HandleNotificationAsync( GuildAvailableNotification notification, CancellationToken cancellationToken) { var guild = notification.Guild; using var logScope = UserMetricsLogMessages.BeginGuildScope(_logger, guild.Id); UserMetricsLogMessages.GuildAvailableHandling(_logger); DoGuildStats(null, guild); UserMetricsLogMessages.GuildAvailableHandled(_logger); return(Task.CompletedTask); }
public Task HandleNotificationAsync( UserLeftNotification notification, CancellationToken cancellationToken) { var guild = notification.GuildUser.Guild; using var logScope = UserMetricsLogMessages.BeginGuildScope(_logger, guild.Id); UserMetricsLogMessages.UserLeftHandling(_logger); DoGuildStats(UserLeftCounterName, guild); UserMetricsLogMessages.UserLeftHandled(_logger); return(Task.CompletedTask); }
public async Task HandleNotificationAsync( MessageReceivedNotification notification, CancellationToken cancellationToken) { var message = notification.Message; var channel = message.Channel; var guild = (channel as IGuildChannel)?.Guild; var author = message.Author; using var logScope = UserMetricsLogMessages.BeginMessageScope(_logger, guild?.Id, channel.Id, author.Id, message.Id); UserMetricsLogMessages.MessageReceivedHandling(_logger); if (guild is null) { UserMetricsLogMessages.IgnoringNonGuildMessage(_logger); return; } if (author.IsBot || author.IsWebhook) { UserMetricsLogMessages.IgnoringNonHumanMessage(_logger); return; } var isOnTopic = true; try { UserMetricsLogMessages.ChannelParticipationFetching(_logger); isOnTopic = await _designatedChannelService.ChannelHasDesignationAsync( guild.Id, channel.Id, DesignatedChannelType.CountsTowardsParticipation, cancellationToken); UserMetricsLogMessages.ChannelParticipationFetched(_logger, isOnTopic); } catch (Exception ex) { UserMetricsLogMessages.ChannelParticipationFetchFailed(_logger, ex); } var isRanked = false; try { UserMetricsLogMessages.UserRankFetching(_logger); isRanked = await _designatedRoleService.RolesHaveDesignationAsync( guild.Id, ((IGuildUser)author).RoleIds, DesignatedRoleType.Rank, cancellationToken); UserMetricsLogMessages.UserRankFetched(_logger, isRanked); } catch (Exception ex) { UserMetricsLogMessages.UserRankFetchFailed(_logger, ex); } var tags = new[] { $"guild:{guild.Name}", $"channel:{channel.Name}", $"offtopic:{!isOnTopic}", $"has_role:{isRanked}" }; _dogStatsd.Increment(MessageReceivedCounterName, tags: tags); UserMetricsLogMessages.MessageReceivedHandled(_logger); }