Пример #1
0
    public async Task <IResult> DeleteBanAsync(long banID)
    {
        var getBan = await _bans.GetBanAsync(_context.GuildID.Value, banID);

        if (!getBan.IsSuccess)
        {
            return(getBan);
        }

        var ban = getBan.Entity;

        // This has to be done before the warning is actually deleted - otherwise, the lazy loader is removed and
        // navigation properties can't be evaluated
        var notifyResult = await _logging.NotifyUserUnbannedAsync(ban, _context.User.ID);

        if (!notifyResult.IsSuccess)
        {
            return(notifyResult);
        }

        var deleteBan = await _bans.DeleteBanAsync(ban);

        if (!deleteBan.IsSuccess)
        {
            return(deleteBan);
        }

        return(await _guildAPI.RemoveGuildBanAsync(_context.GuildID.Value, ban.User.DiscordID));
    }
Пример #2
0
        public async Task <RuntimeResult> DeleteBanAsync(long banID)
        {
            var getBan = await _bans.GetBanAsync(this.Context.Guild, banID);

            if (!getBan.IsSuccess)
            {
                return(getBan.ToRuntimeResult());
            }

            var ban = getBan.Entity;

            // This has to be done before the warning is actually deleted - otherwise, the lazy loader is removed and
            // navigation properties can't be evaluated
            var rescinder = await this.Context.Guild.GetUserAsync(this.Context.User.Id);

            var notifyResult = await _logging.NotifyUserUnbannedAsync(ban, rescinder);

            if (!notifyResult.IsSuccess)
            {
                return(notifyResult.ToRuntimeResult());
            }

            var deleteBan = await _bans.DeleteBanAsync(ban);

            if (!deleteBan.IsSuccess)
            {
                return(deleteBan.ToRuntimeResult());
            }

            await this.Context.Guild.RemoveBanAsync((ulong)ban.User.DiscordID);

            return(RuntimeCommandResult.FromSuccess("Ban rescinded."));
        }
        private async Task <OperationResult> RescindBanIfExpiredAsync
        (
            ChannelLoggingService loggingService,
            BanService bans,
            SocketGuild guild,
            UserBan ban,
            CancellationToken ct
        )
        {
            if (ct.IsCancellationRequested)
            {
                return(OperationResult.FromError("Operation was cancelled."));
            }

            if (!(ban.ExpiresOn <= DateTime.UtcNow))
            {
                // No rescinding is needed, so we'll just bail out
                return(OperationResult.FromSuccess());
            }

            var rescinder    = guild.GetUser(this.Client.CurrentUser.Id);
            var notifyResult = await loggingService.NotifyUserUnbannedAsync(ban, rescinder);

            if (!notifyResult.IsSuccess)
            {
                return(OperationResult.FromError(notifyResult));
            }

            var deleteResult = await bans.DeleteBanAsync(ban, ct);

            if (!deleteResult.IsSuccess)
            {
                return(OperationResult.FromError(deleteResult));
            }

            try
            {
                await guild.RemoveBanAsync((ulong)ban.User.DiscordID);
            }
            catch (HttpException hex) when(hex.HttpCode == HttpStatusCode.NotFound)
            {
                // Already unbanned
                return(OperationResult.FromSuccess());
            }
            catch (Exception ex)
            {
                return(OperationResult.FromError(ex));
            }

            return(OperationResult.FromSuccess());
        }