コード例 #1
0
        public async Task CleanupOops()
        {
            var systemContext = new SystemAppContext();
            var utcNow        = DateTime.UtcNow;

            var suspensions = await suspensionRepository.GetSuspensions(DateTime.UtcNow.AddYears(-1)).ConfigureAwait(false);

            var timeOfOops = DateTime.Parse("2020-10-04T01:18:14.7468436Z");
            var timeOfFix  = new DateTime(2020, 10, 7, 22, 0, 0);

            var suspensionsFromTime = suspensions.Where(x => x.Timestamp >= timeOfOops && x.Timestamp <= timeOfFix).ToList();

            var systemSuspensionsThatNeedReplay = suspensionsFromTime.Where(x => x.SuspensionSource == SuspensionSource.System);

            foreach (var suspension in systemSuspensionsThatNeedReplay)
            {
                suspension.UpdateValidity(true, "Tranquiliza made a mistake, rolling back system bans in the period to replay", systemContext, DateTime.UtcNow);

                await suspensionRepository.Save(suspension).ConfigureAwait(false);
            }

            var names = systemSuspensionsThatNeedReplay.Select(x => x.Username).Distinct().ToList();

            var actualSuspensions = suspensionsFromTime.Where(x => names.Contains(x.Username) && x.SuspensionSource != SuspensionSource.System);

            foreach (var suspension in actualSuspensions)
            {
                suspension.UpdateAuditedState(false, systemContext, utcNow);

                await suspensionRepository.Save(suspension).ConfigureAwait(false);
            }
        }
コード例 #2
0
        private async Task MarkActiveSuspensionsForUserAsUndone(string username, string undoneBy, DateTime timeOfSuspension, IMessageDispatcher messageDispatcher)
        {
            var suspensionsForUser = await suspensionRepository.GetSuspensionsForUser(username).ConfigureAwait(false);

            foreach (var activeSuspension in suspensionsForUser.Where(x => x.IsActive(timeOfSuspension)))
            {
                activeSuspension.MarkSuspensionAsUndone(undoneBy);
                await suspensionRepository.Save(activeSuspension).ConfigureAwait(false);

                await messageDispatcher.Publish(new SuspensionUpdatedEvent
                {
                    ChannelOfOrigin = activeSuspension.ChannelOfOrigin,
                    SuspensionId    = activeSuspension.SuspensionId
                }).ConfigureAwait(false);
            }
        }
コード例 #3
0
        public async Task <IResult <Suspension> > RemoveTagFrom(Guid suspensionId, Guid tagId, IApplicationContext context)
        {
            var fetch = await RetrieveSuspensionAndCheckAccess(suspensionId, context).ConfigureAwait(false);

            if (fetch.State != ResultState.Success)
            {
                return(fetch);
            }

            var suspension = fetch.Data;

            var tag = await tagRepository.Get(tagId).ConfigureAwait(false);

            suspension.RemoveTag(tag, context, datetimeProvider.UtcNow);
            await suspensionRepository.Save(suspension).ConfigureAwait(false);

            await PublishSuspensionUpdatedEvent(suspension).ConfigureAwait(false);

            return(Result <Suspension> .Succeeded(suspension));
        }
コード例 #4
0
        /// <summary>
        /// Run daily to check old unaudited if they can be tagged by the machine!
        /// </summary>
        /// <returns></returns>
        public async Task AttemptTagUnauditedSuspensions()
        {
            try
            {
                var suspensions = await suspensionRepository.GetSuspensions(datetimeProvider.UtcNow.AddYears(-1)).ConfigureAwait(false);

                foreach (var suspension in suspensions.Where(x => !x.Audited && !x.InvalidSuspension))
                {
                    var predicted = await PredictTagsForSuspension(suspension).ConfigureAwait(false);

                    if (predicted != null)
                    {
                        await suspensionRepository.Save(predicted).ConfigureAwait(false);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError("Was unable to process something in the data analyser, this is the stack trace: {arg}", ex.Message);
            }
        }
コード例 #5
0
        public async Task CreateBansFor(List <string> usernames, string channelOfOrigin)
        {
            var utcNow = DateTime.UtcNow;

            var systemContext = new SystemAppContext();

            var botTag = await tagRepository.Get(Guid.Parse("FD77CBEE-10C0-43F5-8FDD-D30F9775520A")).ConfigureAwait(false);

            var chatMessage = new ChatMessage(
                utcNow,
                "",
                "",
                "",
                "",
                false,
                false);

            var fakedChatMessages = new List <ChatMessage> {
                chatMessage
            };

            foreach (var username in usernames)
            {
                var suspension = Suspension.CreateBan(username, channelOfOrigin, utcNow, fakedChatMessages, true);
                suspension.TryAddTag(botTag, systemContext, utcNow);

                foreach (var usernameOfBot in usernames)
                {
                    if (usernameOfBot == username)
                    {
                        continue;
                    }

                    suspension.AddUserLink(usernameOfBot, "Bots of same origin", systemContext, utcNow);
                }

                await suspensionRepository.Save(suspension).ConfigureAwait(false);
            }
        }