diff --git a/Dockerfile b/Dockerfile index 07fdcdd38a324177decee1cdded18de054045c33..ed7f3064d559faed972678788b2a2a2f3232533a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM node:alpine LABEL mantainer "Diego Dorgam <diego.dorgam@rocket.chat>" ENV HUBOT_LANG='en' \ - HUBOT_CORPUS='corpus.yml' \ + HUBOT_CORPUS='training_data/corpus.yml' \ HUBOT_ADAPTER=rocketchat \ HUBOT_OWNER=RocketChat \ HUBOT_NAME=HubotNatural \ diff --git a/docker-compose.yml b/docker-compose.yml index 31af4837fa734a58d94f13c29c7f8b102045ffc6..afaa03e066d540d6356c751fc29aa897d1c76872 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,7 +50,7 @@ services: - HUBOT_OWNER=RocketChat - HUBOT_DESCRIPTION='Hubot natural language processing' - HUBOT_LOG_LEVEL=debug - - HUBOT_CORPUS=corpus.yml + - HUBOT_CORPUS=training_data/corpus.yml - HUBOT_LANG=pt - RESPOND_TO_DM=true - RESPOND_TO_LIVECHAT=true diff --git a/scripts/bot/index.coffee b/scripts/bot/index.coffee index 7e1baa44b4d904b030b0a74f71a73cd480064d40..5a714747921039ab4bc39bdbcdf91f09f0718e51 100644 --- a/scripts/bot/index.coffee +++ b/scripts/bot/index.coffee @@ -135,9 +135,8 @@ clearErrors = (res) -> key = 'errors_'+res.envelope.room+'_'+res.envelope.user.id res.robot.brain.set(key, 0) -module.exports = (_config, _configPath, robot) -> +module.exports = (_config, robot) -> global.config = _config - global.configPath = _configPath global.usersAndRoles = getUserRoles(robot) diff --git a/scripts/events/configure.coffee b/scripts/events/configure.coffee index e1b520d98e319d530959e528a2020bc8263f1014..74621f6dd6f5a51d0b7a8103ad63c130ba12a05d 100644 --- a/scripts/events/configure.coffee +++ b/scripts/events/configure.coffee @@ -1,10 +1,9 @@ path = require 'path' natural = require 'natural' -{msgVariables, stringElseRandomKey, loadConfigfile} = require path.join '..', 'lib', 'common.coffee' +{msgVariables, stringElseRandomKey, loadConfigfile, getConfigFilePath} = require '../lib/common' {checkRole} = require path.join '..', 'lib', 'security.coffee' answers = {} -# usersAndRoles = getUserRoles() class configure constructor: (@interaction) -> @@ -40,7 +39,7 @@ class configure retrain: (msg) -> console.log 'inside retrain' scriptPath = path.join __dirname, '..' - global.config = loadConfigfile(global.configPath) + global.config = loadConfigfile getConfigFilePath() global.train() type = @interaction.type?.toLowerCase() or 'random' diff --git a/scripts/index.coffee b/scripts/index.coffee index 998df3849b5f81e1c3b084ca9a5d393289d869cb..fd66a27959bf9e91bcc23b6e41205f7fca9de908 100644 --- a/scripts/index.coffee +++ b/scripts/index.coffee @@ -1,18 +1,16 @@ -path = require 'path' +require 'coffeescript/register' -{loadConfigfile} = require path.join path.join __dirname, 'lib', 'common.coffee' -chatbot = require path.join __dirname, 'bot', 'index.coffee' +path = require 'path' +fs = require 'fs' -hubotPath = module.parent.filename -hubotPath = path.dirname hubotPath for [1..4] -corpus = (process.env.HUBOT_CORPUS || 'corpus.yml') -global.configPath = path.join hubotPath, 'training_data', corpus +{loadConfigfile, getConfigFilePath} = require './lib/common' +chatbot = require './bot/index' try - global.config = loadConfigfile global.configPath + global.config = loadConfigfile getConfigFilePath() catch err process.exit() -chatbot = chatbot.bind null, global.config, global.configPath +chatbot = chatbot.bind null, global.config module.exports = chatbot diff --git a/scripts/lib/common.coffee b/scripts/lib/common.coffee index 63c178f82a9458fd005892544db5bae2ee3d633b..3ea95ae6eee00e09e7e49351f1253d4a30501782 100644 --- a/scripts/lib/common.coffee +++ b/scripts/lib/common.coffee @@ -24,6 +24,9 @@ common.regexEscape = (string) -> #http://stackoverflow.com/a/6969486 string.replace /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&" +common.getConfigFilePath = () -> + return process.env.HUBOT_CORPUS || 'training_data/corpus.yml' + common.loadConfigfile = (filepath) -> try console.log("Loading corpus: " + filepath)