<commit_before>'use strict'

require('coffee-script').register() // support coffee scripts
if (process.env.NOVE_ENV === 'development') require('dotenv').config() // use local .env

const fs = require('fs')
const resolve = require('path').resolve
const mockery = require('mockery')
const playbook = require('hubot-playbook')
const args = require('./argv')
const Nubot = require('./src')
const coffeeClass = require('./coffee-class')
mockery.enable({ warnOnReplace: false, warnOnUnregistered: false })
mockery.registerSubstitute('hubot', 'nubot')

// TODO: refactor all script loading as robot methods
// This attempts to load two fixed paths before using options, so it would load
// all three if they existed. The option should *override* the default, not add.
function loadScripts (robot, scripts) {
  robot.load(resolve('.', 'scripts'))
  robot.load(resolve('.', 'src', 'scripts'))
  loadExternalScripts(robot)
  scripts.forEach((scriptPath) => {
    if (scriptPath[0] === '/') return robot.load(scriptPath)
    robot.load(resolve('.', scriptPath))
  })
}

function loadExternalScripts (robot) {
  const externalScripts = resolve('.', 'external-scripts.json')
  if (!fs.existsSync(externalScripts)) return
  fs.readFile(externalScripts, function (error, data) {
    if (error) throw error
    try {
      robot.loadExternalScripts(JSON.parse(data))
    } catch (error) {
      console.error(`Error parsing JSON data from external-scripts.json: ${error}`)
      process.exit(1)
    }
  })
}

Nubot.start = function (options) {
  let config = Object.assign({}, args, options)
  const robot = Nubot.loadBot(
    config.adapter,
    config.httpd,
    config.name,
    config.alias,
    config.logLevel
  )
  playbook.use(robot) // make playbook available to all scripts
  robot.adapter.on('connected', () => loadScripts(robot, config.scripts))
  robot.run()
  return robot
}

module.exports = coffeeClass(Nubot)<commit_msg>Changed on('connected') to once<commit_after>'use strict'

require('coffee-script').register() // support coffee scripts
if (process.env.NOVE_ENV === 'development') require('dotenv').config() // use local .env

const fs = require('fs')
const resolve = require('path').resolve
const mockery = require('mockery')
const playbook = require('hubot-playbook')
const args = require('./argv')
const Nubot = require('./src')
const coffeeClass = require('./coffee-class')
mockery.enable({ warnOnReplace: false, warnOnUnregistered: false })
mockery.registerSubstitute('hubot', 'nubot')

// TODO: refactor all script loading as robot methods
// This attempts to load two fixed paths before using options, so it would load
// all three if they existed. The option should *override* the default, not add.
function loadScripts (robot, scripts) {
  robot.load(resolve('.', 'scripts'))
  robot.load(resolve('.', 'src', 'scripts'))
  loadExternalScripts(robot)
  scripts.forEach((scriptPath) => {
    if (scriptPath[0] === '/') return robot.load(scriptPath)
    robot.load(resolve('.', scriptPath))
  })
}

function loadExternalScripts (robot) {
  const externalScripts = resolve('.', 'external-scripts.json')
  if (!fs.existsSync(externalScripts)) return
  fs.readFile(externalScripts, function (error, data) {
    if (error) throw error
    try {
      robot.loadExternalScripts(JSON.parse(data))
    } catch (error) {
      console.error(`Error parsing JSON data from external-scripts.json: ${error}`)
      process.exit(1)
    }
  })
}

Nubot.start = function (options) {
  let config = Object.assign({}, args, options)
  const robot = Nubot.loadBot(
    config.adapter,
    config.httpd,
    config.name,
    config.alias,
    config.logLevel
  )
  playbook.use(robot) // make playbook available to all scripts
  robot.adapter.once('connected', () => loadScripts(robot, config.scripts))
  robot.run()
  return robot
}

module.exports = coffeeClass(Nubot)
{'fraction_non_alphanumeric': 0.1470740548938374, 'fraction_numerical': 0.0010357327809425167, 'mean_word_length': 4.365277777777778, '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': '28218', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1163, 'n_words': 310}