Example #1
0
        /// <summary>
        /// Sets the reasons of the given ban.
        /// </summary>
        /// <param name="ban">The ban.</param>
        /// <param name="reason">The reason.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetBanReasonAsync(UserBan ban, string reason)
        {
            if (reason.IsNullOrWhitespace())
            {
                return(ModifyEntityResult.FromError("You must provide some reason for the ban."));
            }

            if (reason.Length > 1024)
            {
                return(ModifyEntityResult.FromError
                       (
                           "The ban is too long. It can be at most 1024 characters."
                       ));
            }

            if (ban.Reason == reason)
            {
                return(ModifyEntityResult.FromError("That's already the ban's reason."));
            }

            ban.Reason = reason;
            ban.NotifyUpdate();

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Example #2
0
    /// <summary>
    /// Sets the reasons of the given ban.
    /// </summary>
    /// <param name="ban">The ban.</param>
    /// <param name="reason">The reason.</param>
    /// <param name="ct">The cancellation token in use.</param>
    /// <returns>A modification result which may or may not have succeeded.</returns>
    public async Task <Result> SetBanReasonAsync
    (
        UserBan ban,
        string reason,
        CancellationToken ct = default
    )
    {
        reason = reason.Trim();

        if (reason.IsNullOrWhitespace())
        {
            return(new UserError("You must provide some reason for the ban."));
        }

        if (reason.Length > 1024)
        {
            return(new UserError
                   (
                       "The ban is too long. It can be at most 1024 characters."
                   ));
        }

        if (ban.Reason == reason)
        {
            return(new UserError("That's already the ban's reason."));
        }

        ban.Reason = reason;
        ban.NotifyUpdate();

        await _database.SaveChangesAsync(ct);

        return(Result.FromSuccess());
    }
Example #3
0
        /// <summary>
        /// Sets the contextually relevant message for the ban.
        /// </summary>
        /// <param name="ban">The ban.</param>
        /// <param name="messageID">The message.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetBanContextMessageAsync
        (
            UserBan ban,
            long messageID
        )
        {
            if (ban.MessageID == messageID)
            {
                return(ModifyEntityResult.FromError("That's already the ban's context message."));
            }

            ban.MessageID = messageID;
            ban.NotifyUpdate();

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Example #4
0
    /// <summary>
    /// Sets the contextually relevant message for the ban.
    /// </summary>
    /// <param name="ban">The ban.</param>
    /// <param name="messageID">The message.</param>
    /// <param name="ct">The cancellation token in use.</param>
    /// <returns>A modification result which may or may not have succeeded.</returns>
    public async Task <Result> SetBanContextMessageAsync
    (
        UserBan ban,
        Snowflake messageID,
        CancellationToken ct = default
    )
    {
        if (ban.MessageID == messageID)
        {
            return(new UserError("That's already the ban's context message."));
        }

        ban.MessageID = messageID;
        ban.NotifyUpdate();

        await _database.SaveChangesAsync(ct);

        return(Result.FromSuccess());
    }
Example #5
0
        /// <summary>
        /// Sets the date and time at which the ban expires.
        /// </summary>
        /// <param name="ban">The ban.</param>
        /// <param name="expiresOn">The date and time at which the ban expires.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetBanExpiryDateAsync
        (
            UserBan ban,
            DateTime expiresOn
        )
        {
            if (ban.ExpiresOn == expiresOn)
            {
                return(ModifyEntityResult.FromError("That's already the ban's expiry date."));
            }

            if (expiresOn < DateTime.UtcNow)
            {
                return(ModifyEntityResult.FromError("Bans can't expire in the past."));
            }

            ban.ExpiresOn = expiresOn;
            ban.NotifyUpdate();

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Example #6
0
    /// <summary>
    /// Sets the date and time at which the ban expires.
    /// </summary>
    /// <param name="ban">The ban.</param>
    /// <param name="expiresOn">The date and time at which the ban expires.</param>
    /// <param name="ct">The cancellation token in use.</param>
    /// <returns>A modification result which may or may not have succeeded.</returns>
    public async Task <Result> SetBanExpiryDateAsync
    (
        UserBan ban,
        DateTimeOffset expiresOn,
        CancellationToken ct = default
    )
    {
        if (ban.ExpiresOn == expiresOn)
        {
            return(new UserError("That's already the ban's expiry date."));
        }

        if (expiresOn < DateTimeOffset.UtcNow)
        {
            return(new UserError("Bans can't expire in the past."));
        }

        ban.ExpiresOn = expiresOn;
        ban.NotifyUpdate();

        await _database.SaveChangesAsync(ct);

        return(Result.FromSuccess());
    }