Exemple #1
0
        public bool ContainsBadWord(ChatMessage message)
        {
            var isInfraction = wordFilterService.GetWordFilters().Any(x => message.Message.Contains(x.Word));

            if (isInfraction)
            {
                message.AddInfraction(new MessageInfraction
                {
                    InfractionType = MessageInfractionTypes.ContainsBadWord
                });
            }

            return(isInfraction);
        }
Exemple #2
0
        public bool HasTooManyDuplicateCharacters(ChatMessage message)
        {
            var isInfraction = Regex.IsMatch(message.Message, @"(.)\1{10,}");

            if (isInfraction)
            {
                message.AddInfraction(new MessageInfraction
                {
                    InfractionType = MessageInfractionTypes.HasTooManyDuplicateCharacters
                });
            }

            return(isInfraction);
        }
Exemple #3
0
        public bool ContainsWordTooLong(ChatMessage message)
        {
            var isInfraction = message.Message.Split(' ').Any(x => x.Length >= 20);

            if (isInfraction)
            {
                message.AddInfraction(new MessageInfraction
                {
                    InfractionType = MessageInfractionTypes.ContainsWordTooLong
                });
            }

            return(isInfraction);
        }
Exemple #4
0
        /// <summary>
        /// Author has already posted this same message several times in a short period of time
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool MessageRepeatedTooOften(ChatMessage message)
        {
            var startDate = DateTime.UtcNow.AddMinutes(-60);

            var isInfraction = db.Messages
                               .Where(x => x.Date > startDate)
                               .Count(x => x.AuthorId == message.AuthorId && x.Message == message.Message) > 5;

            if (isInfraction)
            {
                message.AddInfraction(new MessageInfraction
                {
                    InfractionType = MessageInfractionTypes.MessageRepeatedTooOften
                });
            }

            return(isInfraction);
        }
Exemple #5
0
        public bool HasTooManyDuplicateWords(ChatMessage message)
        {
            var wordGroups = message.Message.Split(' ')
                             .GroupBy(x => new { x })
                             .Select(s => new { s.Key, Count = s.Count() });

            // TODO: max duplicate words should be configurable
            var isInfraction = wordGroups.Any(x => x.Count >= 5);

            if (isInfraction)
            {
                message.AddInfraction(new MessageInfraction
                {
                    InfractionType = MessageInfractionTypes.HasTooManyDuplicateWords
                });
            }

            return(isInfraction);
        }