Skip to content

Handle messages above the character limit #653

Closed
@hkwu

Description

@hkwu

There's currently nothing to handle messages which exceed the 2000 character limit.

Ideally the client should:

  • split messages over the limit and send them as individual messages
  • prefer splits by lines instead of characters to make the messages less awkward to read
  • re-wrap code blocks that have been split over messages (preserving the syntax highlighting)

Sample implementation (taken from here):

const MESSAGE_CHAR_LIMIT = 2000;

const splitString = (string, prepend = '', append = '') => {
  if (string.length <= MESSAGE_CHAR_LIMIT) {
    return [string];
  }

  const splitIndex = string.lastIndexOf('\n', MESSAGE_CHAR_LIMIT - prepend.length - append.length);
  const sliceEnd = splitIndex > 0 ? splitIndex : MESSAGE_CHAR_LIMIT - prepend.length - append.length;
  const rest = splitString(string.slice(sliceEnd), prepend, append);

  return [`${string.slice(0, sliceEnd)}${append}`, `${prepend}${rest[0]}`, ...rest.slice(1)];
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions