<commit_before>import { EventEmitter } from 'events';

const ANSWER_THRESHOLD = 10;

/**
 * Base class of all classes
 */
export default class Base extends EventEmitter {
  constructor(method) {
    super();

    this.method = method;
    this.properties = {};
  }

  /**
   * Sends the message, you should only use this method yourself if
   * you are extending this class. Normally you should call bot.send(message)
   *
   * Events: message:sent => Emitted after sending the message to API, gets the
   * 												  API's response
   *
   *			message:answer => Emitted when your message gets an answer from
   *				                 the contact (reply in case of groups)
   *				                 gets the Update object containing message
   *
   * @param  {object} bot
   * @return {promise} returns a promise, resolved with message:answer
   */
  send(bot) {
    if (this._keyboard) {
      const replyMarkup = JSON.stringify(this._keyboard.getProperties());
      this.properties.reply_markup = replyMarkup;
    }

    let messageId;
    return new Promise((resolve, reject) => {
      bot.api[this.method](this.properties).then(response => {
        messageId = response.result.message_id;
        this.emit('message:sent', response);
      }).catch(reject);

      if (this._keyboard.one_time_keyboard) {
        this._keyboard.replyMarkup = '';<commit_msg>Allow sending messages longer than 4096 chars<commit_after>import { EventEmitter } from 'events';

const ANSWER_THRESHOLD = 10;
const MSG_MAX_LENGTH = 4096;

/**
 * Base class of all classes
 */
export default class Base extends EventEmitter {
  constructor(method) {
    super();

    this.method = method;
    this.properties = {};
  }

  /**
   * Sends the message, you should only use this method yourself if
   * you are extending this class. Normally you should call bot.send(message)
   *
   * Events: message:sent => Emitted after sending the message to API, gets the
   * 												  API's response
   *
   *			message:answer => Emitted when your message gets an answer from
   *				                 the contact (reply in case of groups)
   *				                 gets the Update object containing message
   *
   * @param  {object} bot
   * @return {promise} returns a promise, resolved with message:answer
   */
  send(bot) {
    if (this._keyboard) {
      const replyMarkup = JSON.stringify(this._keyboard.getProperties());
      this.properties.reply_markup = replyMarkup;
    }

    let messageId;
    return new Promise((resolve, reject) => {
      let promiseChain;

      if (this.method === 'sendMessage' && this.properties.text.length > MSG_MAX_LENGTH) {
        promiseChain = Promise.resolve();
        const textChunks = this.properties.text.match(new RegExp(`.{1,${MSG_MAX_LENGTH}}`, 'g'));

        textChunks.forEach(chunk => {
          const properties = Object.assign({}, this.properties, { text: chunk });
          delete properties.parse_mode; // any unclosed tags, text modifiers will not send out, send as pure text
          promiseChain = promiseChain.then(() => bot.api[this.method](properties));
        });
      } else {
        promiseChain = bot.api[this.method](this.properties);
      }

      promiseChain.then(response => {
        messageId = response.result.message_id;
        this.emit('message:sent', response);
      }).catch(reject);

      if (this._keyboard.one_time_keyboard) {
        this._keyboard.replyMarkup = '';
{'fraction_non_alphanumeric': 0.1095611740773031, 'fraction_numerical': 0.003777971519907004, 'mean_word_length': 2.6891747052518755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '64954', 'n_tokens_mistral': 1023, 'n_tokens_neox': 970, 'n_words': 277}