Skip to content
Snippets Groups Projects
Unverified Commit 6ca4b066 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into develop

parents 033dde29 563e94bb
No related branches found
No related tags found
No related merge requests found
......@@ -52,7 +52,7 @@ class RocketChatAdapter extends Hubot.Adapter
#
# Returns nothing.
send: (envelope, strings...) ->
console.log 'ROCKETCHATADAPTER -> send'.blue
console.log 'ROCKETCHATADAPTER -> send'.blue if DEBUG
# console.log envelope, strings
sendHelper @robot, envelope, strings, (string) =>
console.log "send #{envelope.room}: #{string} (#{envelope.user.id})" if DEBUG
......@@ -65,7 +65,7 @@ class RocketChatAdapter extends Hubot.Adapter
#
# Returns nothing.
emote: (envelope, strings...) ->
console.log 'ROCKETCHATADAPTER -> emote'.blue
console.log 'ROCKETCHATADAPTER -> emote'.blue if DEBUG
sendHelper @robot, envelope, strings, (string) =>
console.log "emote #{envelope.rid}: #{string} (#{envelope.u.username})" if DEBUG
return @priv envelope, "*** #{string} ***" if envelope.message.private
......@@ -76,7 +76,7 @@ class RocketChatAdapter extends Hubot.Adapter
# Priv: our extension -- send a PM to user
priv: (envelope, strings...) ->
console.log 'ROCKETCHATADAPTER -> priv'.blue
console.log 'ROCKETCHATADAPTER -> priv'.blue if DEBUG
sendHelper @robot, envelope, strings, (string) ->
console.log "priv #{envelope.room}: #{string} (#{envelope.user.id})" if DEBUG
Meteor.call "sendMessage",
......@@ -94,7 +94,7 @@ class RocketChatAdapter extends Hubot.Adapter
#
# Returns nothing.
reply: (envelope, strings...) ->
console.log 'ROCKETCHATADAPTER -> reply'.blue
console.log 'ROCKETCHATADAPTER -> reply'.blue if DEBUG
if envelope.message.private
@priv envelope, strings...
else
......@@ -107,7 +107,7 @@ class RocketChatAdapter extends Hubot.Adapter
#
# Returns nothing.
topic: (envelope, strings...) ->
console.log 'ROCKETCHATADAPTER -> topic'.blue
console.log 'ROCKETCHATADAPTER -> topic'.blue if DEBUG
# Public: Raw method for playing a sound in the chat source. Extend this.
#
......@@ -116,13 +116,13 @@ class RocketChatAdapter extends Hubot.Adapter
#
# Returns nothing
play: (envelope, strings...) ->
console.log 'ROCKETCHATADAPTER -> play'.blue
console.log 'ROCKETCHATADAPTER -> play'.blue if DEBUG
# Public: Raw method for invoking the bot to run. Extend this.
#
# Returns nothing.
run: ->
console.log 'ROCKETCHATADAPTER -> run'.blue
console.log 'ROCKETCHATADAPTER -> run'.blue if DEBUG
@robot.emit 'connected'
@robot.brain.mergeData {}
# @robot.brain.emit 'loaded'
......@@ -131,16 +131,15 @@ class RocketChatAdapter extends Hubot.Adapter
#
# Returns nothing.
close: ->
console.log 'ROCKETCHATADAPTER -> close'.blue
console.log 'ROCKETCHATADAPTER -> close'.blue if DEBUG
class InternalHubotReceiver
constructor: (message) ->
#console.log message
console.log message if DEBUG
if message.u.username isnt InternalHubot.name
room = RocketChat.models.Rooms.findOneById message.rid
if room.t is 'c'
console.log message
InternalHubotUser = new Hubot.User(message.u.username, room: message.rid)
InternalHubotTextMessage = new Hubot.TextMessage(InternalHubotUser, message.msg, message._id)
InternalHubot.adapter.receive InternalHubotTextMessage
......@@ -175,46 +174,6 @@ class HubotScripts
console.log "can't load #{scriptFile}".red
console.log e
# console.log __meteor_bootstrap__.serverDir
# npm/rocketchat_internal-hubot/node_modules
# packages/rocketchat_internal-hubot.js
# # load all scripts in scripts/
# console.log path.resolve '.'
# scriptPath = path.resolve __dirname, 'scripts'
# console.log scriptPath
# for file in fs.readdirSync(scriptPath)
# continue unless /\.(coffee|js)$/.test(file)
# robot.loadFile scriptPath, file
# return
# # load all scripts from hubot-scripts
# scriptPath = path.resolve __dirname, 'node_modules', 'hubot-scripts', 'src', 'scripts'
# scripts = require './hubot-scripts.json'
# robot.loadHubotScripts scriptPath, scripts
# robot.parseHelp path.join scriptPath, 'meme_captain.coffee'
# # load all hubot-* modules from package.json
# packageJson = require './package.json'
# pkgs = (pkg for own pkg, version of packageJson.dependencies when !/^(coffee-script|hubot-scripts|hubot-help)$/.test(pkg))
# pkgs.forEach (p) -> (require p)(robot)
# # A special hack for hubot-help: ensure it replies via pm
# privRobot = Object.create robot
# privRobot.respond = (regex, cb) ->
# robot.respond regex, (resp) ->
# resp.message.private = true
# cb(resp)
# (require 'hubot-help')(privRobot)
# # A special hack for meme_captain: change its "respond" invocations to "hear" so that it memes everywhere.
# memecaptain = require './node_modules/hubot-scripts/src/scripts/meme_captain'
# memecaptain
# respond: (regex, cb) ->
# robot.hear regex, (msg) ->
# cb(msg) if msg.envelope.room is 'general/0' or /^\s*[@]?(rocket)?bot\b/i.test(msg.message.text)
sendHelper = Meteor.bindEnvironment (robot, envelope, strings, map) ->
while strings.length > 0
string = strings.shift()
......@@ -236,60 +195,11 @@ init = =>
HubotScripts(InternalHubot)
InternalHubot.run()
# InternalHubot.hear /^test/i, (res) ->
# res.send "Test? TESTING? WE DON'T NEED NO TEST, EVERYTHING WORKS!"
if RocketChat.settings.get 'InternalHubot_Enabled'
RocketChat.callbacks.add 'afterSaveMessage', InternalHubotReceiver, RocketChat.callbacks.priority.LOW, 'InternalHubot'
else
RocketChat.callbacks.remove 'afterSaveMessage', 'InternalHubot'
# Meteor.startup ->
# console.log InternalHubot;
# # what's (the regexp for) my name?
# robot.respond /(?:)/, -> false
# mynameRE = robot.listeners.pop().regex
# # register scripts
# HubotScripts(robot)
# Object.keys(share.hubot).forEach (scriptName) ->
# console.log "Loading hubot script: #{scriptName}"
# share.hubot[scriptName](robot)
# # register our nick
# n = Meteor.call 'newNick', {name: 'rocketbot'}
# Meteor.call 'setTag', {type:'nicks', object:n._id, name:'Gravatar', value:'rocket@printf.net', who:n.canon}
# # register our presence in general chat
# keepalive = -> Meteor.call 'setPresence',
# u:
# username: 'rocketbot'
# rid: 'GENERAL'
# present: true
# foreground: true
# keepalive()
# Meteor.setInterval keepalive, 30*1000 # every 30s refresh presence
# # listen to the chat room, ignoring messages sent before we startup
# startup = true
# ChatMessage.find({}).observe
# added: (message) ->
# return if startup
# return if message.u.username is "rocketbot" or message.u.username is ""
# return if message.system or message.action or message.oplog or message.bodyIsHtml
# console.log "Received from #{message.u.username} in #{message.rid}: #{message.body}"\
# if DEBUG
# user = new Hubot.User(message.u.username, room: message.rid)
# tm = new Hubot.TextMessage(user, message.body, message._id)
# tm.private = message.to?
# # if private, ensure it's treated as a direct address
# if tm.private and not mynameRE.test(tm.text)
# tm.text = "#{robot.name} #{tm.text}"
# adapter.receive tm
# startup = false
# Meteor.call "sendMessage",
# rid: 'GENERAL'
# msg: 'wakes up'
# u:
# username: "rocketbot"
# action: true
Meteor.startup ->
init()
RocketChat.models.Settings.findByIds([ 'InternalHubot_Username', 'InternalHubot_Enabled', 'InternalHubot_ScriptsToLoad']).observe
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment