public IReadOnlyList <ISendable <ITransmittable> > Create(ISnapshot <Civilian, PublicMessage> snapshot) { var similarValues = snapshot.Context .OfType <IReceived <Civilian, PublicMessage> >() .Where(r => r.Timestamp + _settings.SelfSpamWindow > _timeService.UtcNow) .Where(r => r.Sender.Nick == snapshot.Latest.Sender.Nick) .Select(r => r.Transmission.Text.SimilarTo(snapshot.Latest.Transmission.Text)).ToList(); var similarCount = similarValues.Count(p => p > _settings.MinimumPunishmentSimilarity); return(similarCount < 2 ? (IReadOnlyList <ISendable <ITransmittable> >) new List <ISendable <ITransmittable> >() : new SendableMute(snapshot.Sender(), TimeSpan.FromMinutes(2), $"2m {snapshot.Sender().Nick}: {similarValues.Max():#%} = your past text").Wrap().ToList()); }
public IReadOnlyList <ISendable <ITransmittable> > Create(ISnapshot <Civilian, PublicMessage> snapshot) { var similarValues = snapshot.Context .OfType <IReceived <Civilian, PublicMessage> >() .Where(r => r.Timestamp + _settings.LongSpamWindow > _timeService.UtcNow) .Where(r => r.Transmission.Text.Length >= _settings.LongSpamMinimumLength) .Select(r => r.Transmission.Text.SimilarTo(snapshot.Latest.Transmission.Text)).ToList(); var similarCount = similarValues.Count(p => p > _settings.MinimumPunishmentSimilarity); if (snapshot.Latest.Transmission.Text.Length < _settings.LongSpamMinimumLength || similarCount < 1) { return(new List <ISendable <ITransmittable> >()); } else { var banLength = TimeSpan.FromMinutes((snapshot.Latest.Transmission.Text.Length - _settings.LongSpamMinimumLength) / 10 + 1); return(new SendableMute(snapshot.Sender(), banLength, $"{banLength.ToPretty(_logger)} {snapshot.Sender().Nick}: {similarValues.Max():#%} = past text").Wrap().ToList()); } }