fix(Util): throw an explicit error if a chunk exceeds the max length (#2936)

* fix(Util): throw an explicit error if a chunk exceeds the max length

* refactor(Util): consolidate both errors in splitMessage into one

* revert(Messages): do not unnecessarily change the error code

* revert(Messages): do not remove the word 'the'
This commit is contained in:
SpaceEEC
2018-11-27 21:42:28 +01:00
committed by GitHub
parent 23a16c3a73
commit ecaec29380
2 changed files with 2 additions and 4 deletions

View File

@@ -73,7 +73,7 @@ const Messages = {
TYPING_COUNT: 'Count must be at least 1',
SPLIT_MAX_LEN: 'Message exceeds the max length and contains no split characters.',
SPLIT_MAX_LEN: 'Chunk exceeds the max length and contains no split characters.',
BAN_RESOLVE_ID: (ban = false) => `Couldn't resolve the user ID to ${ban ? 'ban' : 'unban'}.`,
@@ -81,8 +81,6 @@ const Messages = {
SEARCH_CHANNEL_TYPE: 'Target must be a TextChannel, DMChannel, GroupDMChannel, or Guild.',
MESSAGE_SPLIT_MISSING: 'Message exceeds the max length and contains no split characters.',
GUILD_CHANNEL_RESOLVE: 'Could not resolve channel to a guild channel.',
GUILD_VOICE_CHANNEL_RESOLVE: 'Could not resolve channel to a guild voice channel.',
GUILD_CHANNEL_ORPHAN: 'Could not find a parent to this guild channel.',

View File

@@ -56,7 +56,7 @@ class Util {
static splitMessage(text, { maxLength = 2000, char = '\n', prepend = '', append = '' } = {}) {
if (text.length <= maxLength) return text;
const splitText = text.split(char);
if (splitText.length === 1) throw new RangeError('SPLIT_MAX_LEN');
if (splitText.some(chunk => chunk.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');
const messages = [];
let msg = '';
for (const chunk of splitText) {