Exemple #1
0
        private async Task CompositeChatClient_OnUserBanned(UserBannedEvent userBannedEvent)
        {
            var timeOfSuspension = datetimeProvider.UtcNow;
            var chatlogForUser   = await chatRepository.GetMessagesFor(userBannedEvent.Username, userBannedEvent.Channel, suspensionLogSettings.BanChatLogRecordTime, timeOfSuspension).ConfigureAwait(false);

            var userForChannel = await userRepository.GetByTwitchUsername(userBannedEvent.Channel).ConfigureAwait(false);

            var isUnconfirmedSource = userForChannel == null;

            // This is probably going to be followed shortly by better event.
            //if (!isUnconfirmedSource && userBannedEvent.Source == EventSource.IRC)
            //{
            //    logger.LogInformation("Received a ban from {channel}, on person {person}, but it was from channel with mod status, so we're skipping it", userBannedEvent.Channel, userBannedEvent.Username);
            //    return;
            //}

            var messageDispatcher = serviceProvider.GetService(typeof(IMessageDispatcher)) as IMessageDispatcher;

            if (isSystemIssuedBan())
            {
                var systemSuspension = await CreateSystemSuspensionWithEvidence(userBannedEvent.Username, userBannedEvent.Channel, timeOfSuspension, userBannedEvent.BanReason).ConfigureAwait(false);
                await MarkActiveSuspensionsForUserAsOverwritten(userBannedEvent.Username, userBannedEvent.Channel, "SYSTEM BAN", timeOfSuspension, messageDispatcher).ConfigureAwait(false);

                await SaveAndPublishNewSuspension(systemSuspension, messageDispatcher).ConfigureAwait(false);

                return;
            }

            var suspension = Suspension.CreateBan(userBannedEvent.Username, userBannedEvent.Channel, timeOfSuspension, chatlogForUser, isUnconfirmedSource);

            if (suspension.InvalidSuspension)
            {
                await suspensionRepository.Save(suspension).ConfigureAwait(false);

                return;
            }

            await MarkActiveSuspensionsForUserAsOverwritten(userBannedEvent.Username, userBannedEvent.Channel, $"{suspension.SuspensionType}", timeOfSuspension, messageDispatcher).ConfigureAwait(false);

            var analysedSuspension = await dataAnalyser.AttemptToTagSuspension(suspension).ConfigureAwait(false);

            await SaveAndPublishNewSuspension(analysedSuspension, messageDispatcher).ConfigureAwait(false);

            bool isSystemIssuedBan()
            => !isUnconfirmedSource && (string.Equals(userBannedEvent.BannedBy, SYSTEM_USERNAME, StringComparison.OrdinalIgnoreCase) || userBannedEvent.BanReason.StartsWith("[AHS]"));
        }
Exemple #2
0
 private void ChatClient_OnUserBanned(object sender, UserBannedEvent e)
 {
     e.Source = EventSource.IRC;
     PublishUserBannedEvent(e);
 }
Exemple #3
0
 private void PubSub_OnUserBanned(object sender, UserBannedEvent e)
 {
     e.Source = EventSource.PubSub;
     PublishUserBannedEvent(e);
 }
Exemple #4
0
 private void PublishUserBannedEvent(UserBannedEvent e) => OnUserBanned?.Invoke(e);
Exemple #5
0
 private void NewConnection_OnUserBanned(object sender, UserBannedEvent e)
 {
     logger.LogInformation("Received Ban on {arg}, issued by {arg2} in channel {arg3}", e.Username, e.BannedBy, e.Channel);
     OnUserBanned?.Invoke(this, e);
 }