Ejemplo n.º 1
0
        /// <summary>
        /// Sets the reasons of the given warning.
        /// </summary>
        /// <param name="warning">The warning.</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 <ModifyEntityResult> SetWarningReasonAsync
        (
            UserWarning warning,
            string reason,
            CancellationToken ct = default
        )
        {
            if (reason.IsNullOrWhitespace())
            {
                return(ModifyEntityResult.FromError("You must provide some reason for the warning."));
            }

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

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

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

            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the contextually relevant message for the warning.
        /// </summary>
        /// <param name="warning">The warning.</param>
        /// <param name="messageID">The message.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetWarningContextMessageAsync
        (
            UserWarning warning,
            long messageID
        )
        {
            if (warning.MessageID == messageID)
            {
                return(ModifyEntityResult.FromError("That's already the warning's context message."));
            }

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

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Sets the contextually relevant message for the warning.
    /// </summary>
    /// <param name="warning">The warning.</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> SetWarningContextMessageAsync
    (
        UserWarning warning,
        Snowflake messageID,
        CancellationToken ct = default
    )
    {
        if (warning.MessageID == messageID)
        {
            return(new UserError("That's already the warning's context message."));
        }

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

        await _database.SaveChangesAsync(ct);

        return(Result.FromSuccess());
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the date and time at which the warning expires.
        /// </summary>
        /// <param name="warning">The warning.</param>
        /// <param name="expiresOn">The date and time at which the warning expires.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetWarningExpiryDateAsync
        (
            UserWarning warning,
            DateTime expiresOn
        )
        {
            if (warning.ExpiresOn == expiresOn)
            {
                return(ModifyEntityResult.FromError("That's already the warning's expiry date."));
            }

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

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

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Sets the date and time at which the warning expires.
    /// </summary>
    /// <param name="warning">The warning.</param>
    /// <param name="expiresOn">The date and time at which the warning 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> SetWarningExpiryDateAsync
    (
        UserWarning warning,
        DateTimeOffset expiresOn,
        CancellationToken ct = default
    )
    {
        if (warning.ExpiresOn == expiresOn)
        {
            return(new UserError("That's already the warning's expiry date."));
        }

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

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

        await _database.SaveChangesAsync(ct);

        return(Result.FromSuccess());
    }