Example #1
0
        /// <inheritdoc />
        public async Task RemoveActivePunishmentFromDb(ActivePunishment punishment)
        {
            using (var scope = _scopeFactory.CreateScope())
            {
                var activePunishmentService =
                    scope.ServiceProvider.GetRequiredService <IEntityService <ActivePunishment> >();

                await activePunishmentService.Remove(punishment);
            }
        }
Example #2
0
        /// <inheritdoc />
        public async Task <PunishmentResponse> RemovePunishment(ActivePunishment punishment)
        {
            var guild = _client.GetGuild(punishment.User.GuildId);

            var userId = punishment.User.UserId;

            await guild.RemoveBanAsync(userId);

            return(new PunishmentResponse {
                Successful = true
            });
        }
        /// <inheritdoc />
        public async Task <PunishmentResponse> RemovePunishment(ActivePunishment punishment)
        {
            var punishmentResponse = new PunishmentResponse();

            var guild = _client.GetGuild(punishment.User.GuildId);

            var role = guild?.GetRole(punishment.RoleId.Value);

            var user = guild?.Users.FirstOrDefault(x => x.Id == punishment.User.UserId);

            // If role hierarchy has changed since punishment was applied and now the bot doesn't have sufficient privileges, do nothing.
            if (role != null && HasSufficientPrivileges(role, guild))
            {
                await user.RemoveRoleAsync(role);

                punishmentResponse.Successful = true;

                punishmentResponse.StatusMessage = "";
            }
            else
            {
                punishmentResponse.Successful = false;
                if (user != null)
                {
                    punishmentResponse.StatusMessage =
                        $"Moderation Module: Couldn't apply role '{role?.Name ?? "role"}' to user {user.Username} as bot doesn't have appropriate permissions. " +
                        $"Guild Id:{guild.Id}, Role Id: {punishment.RoleId.Value}, User Id: {user.Id}";
                }
                else
                {
                    punishmentResponse.StatusMessage =
                        "Moderation Module: Something went wrong when trying to remove role in the punishment removal job. User was unexpectedly null.";
                }
            }

            return(punishmentResponse);
        }
Example #4
0
 /// <inheritdoc />
 public Task <PunishmentResponse> RemovePunishment(ActivePunishment punishment)
 {
     return(Task.FromResult(new PunishmentResponse {
         Successful = true
     }));
 }
Example #5
0
        public async Task RemovePunishment(ActivePunishment punishment)
        {
            await _punishmentFactory.GetPunishment(punishment.PunishType).RemovePunishment(punishment);

            await _activePunishmentService.RemoveActivePunishmentFromDb(punishment);
        }
Example #6
0
 public string ScheduleActivePunishmentRemoval(ActivePunishment activePunishment)
 {
     return(_jobService.ScheduleJob(() => RemoveActivePunishmentDiscord(activePunishment.Id),
                                    activePunishment.PunishmentExpires));
 }