Beispiel #1
0
        /// <inheritdoc />
        public async Task RescindInfractionAsync(long infractionId, string reason)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.ModerationRescind);

            var infraction = await InfractionRepository.ReadAsync(infractionId);

            if (infraction == null)
            {
                throw new ArgumentException("Infraction does not exist", nameof(infractionId));
            }

            switch (infraction.Type)
            {
            case InfractionType.Mute:
                await DoDiscordUnMuteAsync(infraction.Subject.Id);

                break;

            case InfractionType.Ban:
                await DoDiscordUnBanAsync(infraction.Subject.Id);

                break;
            }

            var actionId = await ModerationActionRepository.CreateAsync(new ModerationActionCreationData()
            {
                Type         = ModerationActionType.InfractionRescinded,
                CreatedById  = AuthorizationService.CurrentUserId.Value,
                Reason       = reason,
                InfractionId = infractionId
            });

            // TODO: Log action to a channel, pulled from IModerationConfigRepository.
        }
Beispiel #2
0
        /// <inheritdoc />
        public async Task CreateInfractionAsync(InfractionType type, ulong subjectId, string reason, TimeSpan?duration)
        {
            AuthorizationService.RequireClaims(_createInfractionClaimsByType[type]);

            switch (type)
            {
            case InfractionType.Mute:
                await DoDiscordMuteAsync(subjectId);

                break;

            case InfractionType.Ban:
                await DoDiscordBanAsync(subjectId);

                break;
            }

            var actionId = await ModerationActionRepository.CreateAsync(new ModerationActionCreationData()
            {
                Type        = ModerationActionType.InfractionCreated,
                CreatedById = AuthorizationService.CurrentUserId.Value,
                Reason      = reason
            });

            var infractionId = await InfractionRepository.CreateAsync(new InfractionCreationData()
            {
                Type           = type,
                SubjectId      = subjectId,
                Duration       = duration,
                CreateActionId = actionId
            });

            await ModerationActionRepository.UpdateAsync(actionId, data =>
            {
                data.InfractionId = infractionId;
            });

            // TODO: Log action to a channel, pulled from IModerationConfigRepository.

            // TODO: Implement InfractionAutoExpirationBehavior (or whatever) to automatically rescind infractions, based on Duration, and notify it here that a new infraction has been created, if it has a duration.
        }