src/Core/Validator.js
/**
     * Check whether a message content / embed comply with discord limits.
     *
     * @static
     * @param {String|MessageObject} content
     * @returns {Boolean} Returns true if the message is valid, otherwise throw an AxonError
     * @memberof Validator
     */
Check whether a message content / embed comply with discord limits.
@static
@param {String|MessageObject} content
@returns {Boolean} Returns true if the message is valid, otherwise throw an AxonError
@memberof Validator
Check whether a message content / embed comply with discord limits . @static @param { String|MessageObject } content @returns { Boolean } Returns true if the message is valid otherwise throw an AxonError @memberof Validator
static checkMessageValidity(content) {
        if (content instanceof Object && content.embed) {
            if (content.content && content.content.length > EMBED_LIMITS.LIMIT_CONTENT) {
                throw new AxonError('Content > 2000', 'MESSAGE');
            }
            if (content.embed.length > EMBED_LIMITS.LIMIT_TOTAL_EMBED) {
                throw new AxonError('Global embed > 6000', 'MESSAGE-EMBED');
            }
            if (content.embed.description && content.embed.description.length > EMBED_LIMITS.LIMIT_DESCRIPTION) {
                throw new AxonError('Description > 2048', 'MESSAGE-EMBED');
            }
            if (content.embed.title && content.embed.title.length > EMBED_LIMITS.LIMIT_TITLE) {
                throw new AxonError('Title > 256', 'MESSAGE-EMBED');
            }
            if (content.embed.author && content.embed.author.name && content.embed.author.name.length > EMBED_LIMITS.LIMIT_AUTHOR_NAME) {
                throw new AxonError('Author > 256', 'MESSAGE-EMBED');
            }
            if (content.embed.footer && content.embed.footer.text && content.embed.footer.text.length > EMBED_LIMITS.LIMIT_FOOTER_TEXT) {
                throw new AxonError('Footer > 2048', 'MESSAGE-EMBED');
            }
            if (content.embed.fields) {
                if (content.embed.fields.length > EMBED_LIMITS.NUMBER_FIELDS) {
                    throw new AxonError('Fields > 25', 'MESSAGE-EMBED');
                }
                for (const field in content.embed.fields) {
                    if (field.name > EMBED_LIMITS.LIMIT_FIELD_NAME || field.value > EMBED_LIMITS.LIMIT_FIELD_VALUE) {
                        throw new AxonError('Field: name > 256 ; value > 1024', 'MESSAGE-EMBED');
                    }
                }
            }
        } else if (typeof content === 'string' && content.length > EMBED_LIMITS.LIMIT_CONTENT) {
            throw new AxonError('Content > 2000', 'MESSAGE');
        }
        return true;
    }
static checkMessageValidity ( content ) { if ( content instanceof Object && content . embed ) { if ( content . content && content . content . length > EMBED_LIMITS . LIMIT_CONTENT ) { throw new AxonError ( 'Content > 2000' , 'MESSAGE' ) ; } if ( content . embed . length > EMBED_LIMITS . LIMIT_TOTAL_EMBED ) { throw new AxonError ( 'Global embed > 6000' , 'MESSAGE-EMBED' ) ; } if ( content . embed . description && content . embed . description . length > EMBED_LIMITS . LIMIT_DESCRIPTION ) { throw new AxonError ( 'Description > 2048' , 'MESSAGE-EMBED' ) ; } if ( content . embed . title && content . embed . title . length > EMBED_LIMITS . LIMIT_TITLE ) { throw new AxonError ( 'Title > 256' , 'MESSAGE-EMBED' ) ; } if ( content . embed . author && content . embed . author . name && content . embed . author . name . length > EMBED_LIMITS . LIMIT_AUTHOR_NAME ) { throw new AxonError ( 'Author > 256' , 'MESSAGE-EMBED' ) ; } if ( content . embed . footer && content . embed . footer . text && content . embed . footer . text . length > EMBED_LIMITS . LIMIT_FOOTER_TEXT ) { throw new AxonError ( 'Footer > 2048' , 'MESSAGE-EMBED' ) ; } if ( content . embed . fields ) { if ( content . embed . fields . length > EMBED_LIMITS . NUMBER_FIELDS ) { throw new AxonError ( 'Fields > 25' , 'MESSAGE-EMBED' ) ; } for ( const field in content . embed . fields ) { if ( field . name > EMBED_LIMITS . LIMIT_FIELD_NAME || field . value > EMBED_LIMITS . LIMIT_FIELD_VALUE ) { throw new AxonError ( 'Field: name > 256 ; value > 1024' , 'MESSAGE-EMBED' ) ; } } } } else if ( typeof content === 'string' && content . length > EMBED_LIMITS . LIMIT_CONTENT ) { throw new AxonError ( 'Content > 2000' , 'MESSAGE' ) ; } return true ; }
Check whether a message content / embed comply with discord limits.
Check whether a message content / embed comply with discord limits .