<commit_before>import _ from 'lodash'
import l from 'chalk-log'

import cocos from '../cocos'
import leaves from '../leaves'
import pkg from '../../package.json'

export default class Palm {

  constructor (params) {
    this.cocos = cocos
    this.leaf = params.talk

    if (this.leaf === 'telegram') {
      this.telegram = new leaves.Telegram(params.telegram)
    } else if (this.leaf === 'cli') {
      this.cli = new leaves.Cli()
    }
  }

  listen () {
    l.note(`Initialized palm v${pkg.version}`)

    this[this.leaf].init()

    this[this.leaf].on('message', text => {
      this.respond({ text })
    })
  }

  respond ({ text }) {
    const getCoco = this.initCoco(text)

    if (getCoco.ok) {
      this[this.leaf].send({ text: getCoco.coco.exec(text) })
    } else {
      this[this.leaf].send({ text: this.cocos.idk.exec() })
    }
  }

  initCoco (text) {
    const a = { ok: false }

    for (const key in this.cocos) {
      _.forEach(this.cocos[key].keywords, keyword => {
        if (text.match(new RegExp(keyword, 'i'))) {
          a.ok = true
          a.coco = this.cocos[key]
        }
      })
    }

    return a
  }
}
<commit_msg>Add send method<commit_after>import _ from 'lodash'
import l from 'chalk-log'

import cocos from '../cocos'
import leaves from '../leaves'
import pkg from '../../package.json'

export default class Palm {

  constructor (params) {
    this.cocos = cocos
    this.leaf = params.talk

    if (this.leaf === 'telegram') {
      this.telegram = new leaves.Telegram(params.telegram)
    } else if (this.leaf === 'cli') {
      this.cli = new leaves.Cli()
    }
  }

  listen () {
    l.note(`Initialized palm v${pkg.version}`)

    this[this.leaf].init()

    this[this.leaf].on('message', text => {
      this.respond({ text })
    })
  }

  send ({ text }) {
    this[this.leaf].send({ text })
  }

  respond ({ text }) {
    const getCoco = this.initCoco(text)

    if (getCoco.ok) {
      this[this.leaf].send({ text: getCoco.coco.exec(text) })
    } else {
      this[this.leaf].send({ text: this.cocos.idk.exec() })
    }
  }

  initCoco (text) {
    const a = { ok: false }

    for (const key in this.cocos) {
      _.forEach(this.cocos[key].keywords, keyword => {
        if (text.match(new RegExp(keyword, 'i'))) {
          a.ok = true
          a.coco = this.cocos[key]
        }
      })
    }

    return a
  }
}

{'fraction_non_alphanumeric': 0.16876574307304787, 'fraction_numerical': 0.0, 'mean_word_length': 2.215924426450742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3780490', 'n_tokens_mistral': 872, 'n_tokens_neox': 836, 'n_words': 182}