Ejemplo n.º 1
0
        private async Task DoRescindInfractionAsync(InfractionSummary infraction)
        {
            if (infraction == null)
            {
                throw new InvalidOperationException("Infraction does not exist");
            }

            await InfractionRepository.TryRescindAsync(infraction.Id, AuthorizationService.CurrentUserId.Value);

            var guild = await DiscordClient.GetGuildAsync(infraction.GuildId);

            switch (infraction.Type)
            {
            case InfractionType.Mute:
                if (!await UserService.GuildUserExistsAsync(guild.Id, infraction.Subject.Id))
                {
                    throw new InvalidOperationException("Cannot unmute a user who is not in the server.");
                }

                var subject = await UserService.GetGuildUserAsync(guild.Id, infraction.Subject.Id);

                await subject.RemoveRoleAsync(await GetDesignatedMuteRoleAsync(guild));

                break;

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

                break;

            default:
                throw new InvalidOperationException($"{infraction.Type} infractions cannot be rescinded.");
            }
        }
Ejemplo n.º 2
0
        private async Task DoRescindInfractionAsync(InfractionSummary infraction)
        {
            if (infraction == null)
            {
                throw new InvalidOperationException("Infraction does not exist");
            }

            await InfractionRepository.TryRescindAsync(infraction.Id, AuthorizationService.CurrentUserId.Value);

            var guild = await GuildService.GetGuildAsync(infraction.GuildId);

            var subject = await UserService.GetGuildUserAsync(guild.Id, infraction.Subject.Id);

            switch (infraction.Type)
            {
            case InfractionType.Mute:
                await subject.RemoveRoleAsync(
                    await GetOrCreateMuteRoleInGuildAsync(guild));

                break;

            case InfractionType.Ban:
                await guild.RemoveBanAsync(subject);

                break;

            default:
                throw new InvalidOperationException($"{infraction.Type} infractions cannot be rescinded.");
            }
        }
Ejemplo n.º 3
0
        private async Task DoRescindInfractionAsync(InfractionSummary infraction, string reason = null, bool isAutoRescind = false)
        {
            RequestOptions GetRequestOptions() => string.IsNullOrEmpty(reason) ? null : new RequestOptions
            {
                AuditLogReason = reason
            };

            if (infraction == null)
            {
                throw new InvalidOperationException("Infraction does not exist");
            }

            if (!isAutoRescind)
            {
                await RequireSubjectRankLowerThanModeratorRankAsync(infraction.GuildId, AuthorizationService.CurrentUserId.Value, infraction.Subject.Id);
            }

            await InfractionRepository.TryRescindAsync(infraction.Id, AuthorizationService.CurrentUserId.Value, reason);

            var guild = await DiscordClient.GetGuildAsync(infraction.GuildId);

            switch (infraction.Type)
            {
            case InfractionType.Mute:
                if (!await UserService.GuildUserExistsAsync(guild.Id, infraction.Subject.Id))
                {
                    Log.Information("Attempted to remove the mute role from {0} ({1}), but they were not in the server.",
                                    infraction.Subject.GetFullUsername(),
                                    infraction.Subject.Id);
                    break;
                }

                var subject = await UserService.GetGuildUserAsync(guild.Id, infraction.Subject.Id);

                await subject.RemoveRoleAsync(await GetDesignatedMuteRoleAsync(guild), GetRequestOptions());

                break;

            case InfractionType.Ban:
                await guild.RemoveBanAsync(infraction.Subject.Id, GetRequestOptions());

                break;

            default:
                throw new InvalidOperationException($"{infraction.Type} infractions cannot be rescinded.");
            }
        }