Skip to content

Commit

Permalink
Avoid splitting messages w/ new lines <= 4000 char
Browse files Browse the repository at this point in the history
  • Loading branch information
redhotvengeance committed Dec 10, 2014
1 parent 218012d commit c6982ee
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,22 @@ class SlackBot extends Adapter
submessages = []

while msg.length > 0
# Split message at last line break, if it exists
chunk = msg.substring(0, MAX_MESSAGE_LENGTH)
breakIndex = chunk.lastIndexOf('\n')
breakIndex = MAX_MESSAGE_LENGTH if breakIndex is -1
if msg.length <= MAX_MESSAGE_LENGTH
submessages.push msg
msg = ''

submessages.push msg.substring(0, breakIndex)
else
# Split message at last line break, if it exists
chunk = msg.substring(0, MAX_MESSAGE_LENGTH)
breakIndex = chunk.lastIndexOf('\n')
breakIndex = MAX_MESSAGE_LENGTH if breakIndex is -1

# Skip char if split on line break
breakIndex++ if breakIndex isnt MAX_MESSAGE_LENGTH
submessages.push msg.substring(0, breakIndex)

msg = msg.substring(breakIndex, msg.length)
# Skip char if split on line break
breakIndex++ if breakIndex isnt MAX_MESSAGE_LENGTH

msg = msg.substring(breakIndex, msg.length)

channel.send m for m in submessages

Expand Down

0 comments on commit c6982ee

Please sign in to comment.