diff options
Diffstat (limited to 'node_modules/discord.js/src/util/SplitMessage.js')
| -rw-r--r-- | node_modules/discord.js/src/util/SplitMessage.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/util/SplitMessage.js b/node_modules/discord.js/src/util/SplitMessage.js new file mode 100644 index 0000000..3833f00 --- /dev/null +++ b/node_modules/discord.js/src/util/SplitMessage.js @@ -0,0 +1,16 @@ +module.exports = function splitMessage(text, { maxLength = 1950, char = '\n', prepend = '', append = '' } = {}) { + if (text.length <= maxLength) return text; + const splitText = text.split(char); + if (splitText.length === 1) throw new Error('Message exceeds the max length and contains no split characters.'); + const messages = ['']; + let msg = 0; + for (let i = 0; i < splitText.length; i++) { + if (messages[msg].length + splitText[i].length + 1 > maxLength) { + messages[msg] += append; + messages.push(prepend); + msg++; + } + messages[msg] += (messages[msg].length > 0 && messages[msg] !== prepend ? char : '') + splitText[i]; + } + return messages; +}; |
