<commit_before>/**
 *
 * wechaty: Wechat for ChatBots.
 *
 * Class Wechaty
 *
 * Licenst: ISC
 * https://github.com/zixia/wechaty
 *
 */
const EventEmitter  = require('events')
const co            = require('co')
const fs            = require('fs')

const log           = require('./npmlog-env')
const UtilLib          = require('./util-lib')

const PuppetWeb     = require('./puppet-web')

const Config = require('./config')

class Wechaty extends EventEmitter {

  constructor({
    type        = process.env.WECHATY_PUPPET    || Config.DEFAULT_PUPPET
    , head      = process.env.WECHATY_HEAD      || Config.DEFAULT_HEAD
    , port      = process.env.WECHATY_PORT      || 0    // 0 for disable port
    , endpoint  = process.env.WECHATY_ENDPOINT          // wechaty.io api endpoint
    , token     = process.env.WECHATY_TOKEN             // token for wechaty.io auth
    , profile   = process.env.WECHATY_PROFILE           // no profile, no session save/restore
  } = {}) {
    log.verbose('Wechaty', 'contructor()')

    super()
    this.type     = type
    this.head     = head
    this.port     = port
    this.token    = token
    this.endpoint = endpoint

    this.profile  = /\.wechaty\.json$/i.test(profile)
                    ? profile
                    : profile + '.wechaty.json'

    this.npmVersion = require('../package.json').version

    this.uuid = UtilLib.guid()
    
    this.inited = false
  }

  toString() { return 'Class Wechaty(' + this.type + ')'}

  version(forceNpm) {
    const dotGitPath  = __dirname + '/../.git'
    const gitLogCmd   = 'cd ' + __dirname + '; git log --oneline -1'

    if (!forceNpm) {
      try {
        fs.accessSync(dotGitPath, fs.F_OK)
        const revision = require('child_process')
                          .execSync(gitLogCmd)
                          .toString().trim()
        return `#git[${revision}]`
      } catch (e) { /* fall safe */ 
        /**
         *  1. .git not exist
         *  2. git log fail
         */<commit_msg>get rid of git stderr when read version<commit_after>/**
 *
 * wechaty: Wechat for ChatBots.
 *
 * Class Wechaty
 *
 * Licenst: ISC
 * https://github.com/zixia/wechaty
 *
 */
const EventEmitter  = require('events')
const co            = require('co')
const fs            = require('fs')

const log           = require('./npmlog-env')
const UtilLib          = require('./util-lib')

const PuppetWeb     = require('./puppet-web')

const Config = require('./config')

class Wechaty extends EventEmitter {

  constructor({
    type        = process.env.WECHATY_PUPPET    || Config.DEFAULT_PUPPET
    , head      = process.env.WECHATY_HEAD      || Config.DEFAULT_HEAD
    , port      = process.env.WECHATY_PORT      || 0    // 0 for disable port
    , endpoint  = process.env.WECHATY_ENDPOINT          // wechaty.io api endpoint
    , token     = process.env.WECHATY_TOKEN             // token for wechaty.io auth
    , profile   = process.env.WECHATY_PROFILE           // no profile, no session save/restore
  } = {}) {
    log.verbose('Wechaty', 'contructor()')

    super()
    this.type     = type
    this.head     = head
    this.port     = port
    this.token    = token
    this.endpoint = endpoint

    this.profile  = /\.wechaty\.json$/i.test(profile)
                    ? profile
                    : profile + '.wechaty.json'

    this.npmVersion = require('../package.json').version

    this.uuid = UtilLib.guid()
    
    this.inited = false
  }

  toString() { return 'Class Wechaty(' + this.type + ')'}

  version(forceNpm) {
    const dotGitPath  = __dirname + '/../.git'
    const gitLogCmd   = 'cd ' + __dirname + '; git log --oneline -1 2>/dev/null'

    if (!forceNpm) {
      try {
        fs.accessSync(dotGitPath, fs.F_OK)
        const revision = require('child_process')
                          .execSync(gitLogCmd)
                          .toString().trim()
        return `#git[${revision}]`
      } catch (e) { /* fall safe */ 
        /**
         *  1. .git not exist
         *  2. git log fail
         */
{'fraction_non_alphanumeric': 0.13384463137060862, 'fraction_numerical': 0.0027214250371103412, 'mean_word_length': 1.8056904927133934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '1624284', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1275, 'n_words': 274}