コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }