From 4627a0f1389038ddf53b8a7b7f6abb9a1d367773 Mon Sep 17 00:00:00 2001
From: Diego Dorgam <diego.dorgam@rocket.chat>
Date: Mon, 9 Oct 2017 18:10:51 -0300
Subject: [PATCH] make the bot less verbose in channels

---
 package.json                 |  4 ++--
 scripts/bot/index.coffee     | 14 ++++++++++----
 scripts/config/corpus-v1.yml |  2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/package.json b/package.json
index 7d484cd..674d08a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "hubot-natural",
-  "version": "0.0.4",
+  "version": "0.0.5",
   "private": true,
   "author": "Diego Dorgam <diego.dorgam@rocket.chat>",
   "description": "NLP YAML oriented chatbot",
@@ -10,7 +10,7 @@
     "hubot-help": "^0.2.2",
     "hubot-scripts": "^2.17.2",
     "hubot-shell": "^1.0.2",
-    "hubot-rocketchat": "^1.0.11",
+    "hubot-rocketchat": "^1.0.12",
     "js-yaml": "^3.2.5",
     "natural": "^0.5.0",
     "pm2": "^2.4.2"
diff --git a/scripts/bot/index.coffee b/scripts/bot/index.coffee
index e3666e8..21da3ea 100644
--- a/scripts/bot/index.coffee
+++ b/scripts/bot/index.coffee
@@ -46,6 +46,7 @@ sendWithNaturalDelay = (msgs, elapsed=0) ->
       cb?()
   , delay
 
+# check these
 livechatTransferHuman = (res) ->
 	setTimeout ->
 		res.robot.adapter.callMethod 'livechat:transfer',
@@ -59,6 +60,7 @@ setUserName = (res, name) ->
 		name: name
 	,
 		_id: res.envelope.room
+#
 
 classifyInteraction = (interaction, classifier) ->
   if Array.isArray interaction.expect
@@ -215,14 +217,18 @@ module.exports = (_config, robot) ->
     currentNode.process.call @, res, msg, subClassifications
 
   robot.hear /(.+)/i, (res) ->
-    # console.log(res)
-    console.log(res.answer)
+    console.log(res)
+    #console.log(res.answer)
     res.sendWithNaturalDelay = sendWithNaturalDelay.bind(res)
     msg = res.match[0].replace res.robot.name+' ', ''
     msg = msg.replace(/^\s+/, '')
     msg = msg.replace(/\s+&/, '')
-
-    processMessage res, msg
+    # check if robot should respond
+    if res.envelope.user.roomType in ['c','p']
+      if (res.message.text.match new RegExp('\\b' + res.robot.name + '\\b', 'i')) or (res.message.text.match new RegExp('\\b' + res.robot.alias + '\\b', 'i'))
+        processMessage res, msg
+    else if res.envelope.user.roomType in ['d','l']
+      processMessage res, msg
 
 # TODO
 # make a function for checking roles
diff --git a/scripts/config/corpus-v1.yml b/scripts/config/corpus-v1.yml
index d2de984..c115fca 100644
--- a/scripts/config/corpus-v1.yml
+++ b/scripts/config/corpus-v1.yml
@@ -156,7 +156,7 @@ interactions:
       trust: .8
       interactions:
         - get-programacao
-        - cancela-programacao
+      #  - cancela-programacao
       # error:
       #   - erro-trilha
     event: respond
-- 
GitLab