Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
8ab21427
Commit
8ab21427
authored
9 years ago
by
Rodrigo Nascimento
Browse files
Options
Downloads
Patches
Plain Diff
Init hubot script loading
parent
0fe159f5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/rocketchat-hubot/hubot.coffee
+39
-33
39 additions, 33 deletions
packages/rocketchat-hubot/hubot.coffee
server/methods/addUserToRoom.coffee
+47
-50
47 additions, 50 deletions
server/methods/addUserToRoom.coffee
with
86 additions
and
83 deletions
packages/rocketchat-hubot/hubot.coffee
+
39
−
33
View file @
8ab21427
...
...
@@ -149,38 +149,44 @@ class RocketBotReceiver
class
HubotScripts
constructor
:
(
robot
)
->
# load all scripts in scripts/
scriptPath
=
path
.
resolve
__dirname
,
'scripts'
for
file
in
fs
.
readdirSync
(
scriptPath
)
continue
unless
/\.(coffee|js)$/
.
test
(
file
)
robot
.
loadFile
scriptPath
,
file
# 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
)
hello
=
Npm
.
require
'hubot-scripts/src/scripts/hello.coffee'
hello
robot
console
.
log
Npm
.
require
'hubot-scripts/src/scripts'
# # 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
...
...
@@ -197,7 +203,7 @@ sendHelper = Meteor.bindEnvironment (robot, envelope, strings, map) ->
RocketBot
=
new
Robot
null
,
null
,
false
,
'rocketbot'
RocketBot
.
alias
=
'bot'
RocketBot
.
adapter
=
new
RocketChatAdapter
RocketBot
#
HubotScripts(RocketBot)
HubotScripts
(
RocketBot
)
RocketBot
.
hear
/test/i
,
(
res
)
->
res
.
send
"Test? TESTING? WE DON'T NEED NO TEST, EVERYTHING WORKS!"
...
...
This diff is collapsed.
Click to expand it.
server/methods/addUserToRoom.coffee
+
47
−
50
View file @
8ab21427
RocketChat
.
addUserToRoom
=
(
userId
,
data
)
->
fromId
=
userId
# console.log '[methods] addUserToRoom -> '.green, 'fromId:', fromId, 'data:', data
room
=
ChatRoom
.
findOne
data
.
rid
# if room.username isnt Meteor.user().username and room.t is 'c'
if
room
.
u
.
username
isnt
Meteor
.
users
.
findOne
(
userId
).
username
and
room
.
t
is
'c'
throw
new
Meteor
.
Error
403
,
'[methods] addUserToRoom -> Not allowed'
# verify if user is already in room
if
room
.
usernames
.
indexOf
(
data
.
username
)
isnt
-
1
return
now
=
new
Date
()
update
=
$push
:
usernames
:
$each
:
[
data
.
username
]
$sort
:
1
newUser
=
Meteor
.
users
.
findOne
username
:
data
.
username
ChatRoom
.
update
data
.
rid
,
update
ChatSubscription
.
insert
rid
:
data
.
rid
ts
:
now
name
:
room
.
name
t
:
room
.
t
open
:
true
alert
:
true
unread
:
1
u
:
_id
:
newUser
.
_id
username
:
data
.
username
ChatMessage
.
insert
rid
:
data
.
rid
ts
:
now
t
:
'au'
msg
:
newUser
.
name
u
:
_id
:
fromId
username
:
Meteor
.
users
.
findOne
(
userId
).
username
return
true
Meteor
.
methods
addUserToRoom
:
(
data
)
->
RocketChat
.
addUserToRoom
Meteor
.
userId
(),
data
fromId
=
Meteor
.
userId
()
# console.log '[methods] addUserToRoom -> '.green, 'fromId:', fromId, 'data:', data
room
=
ChatRoom
.
findOne
data
.
rid
# if room.username isnt Meteor.user().username and room.t is 'c'
if
room
.
u
.
username
isnt
Meteor
.
user
().
username
and
room
.
t
is
'c'
throw
new
Meteor
.
Error
403
,
'[methods] addUserToRoom -> Not allowed'
# verify if user is already in room
if
room
.
usernames
.
indexOf
(
data
.
username
)
isnt
-
1
return
now
=
new
Date
()
update
=
$push
:
usernames
:
$each
:
[
data
.
username
]
$sort
:
1
newUser
=
Meteor
.
users
.
findOne
username
:
data
.
username
ChatRoom
.
update
data
.
rid
,
update
ChatSubscription
.
insert
rid
:
data
.
rid
ts
:
now
name
:
room
.
name
t
:
room
.
t
open
:
true
alert
:
true
unread
:
1
u
:
_id
:
newUser
.
_id
username
:
data
.
username
ChatMessage
.
insert
rid
:
data
.
rid
ts
:
now
t
:
'au'
msg
:
newUser
.
name
u
:
_id
:
fromId
username
:
Meteor
.
user
().
username
return
true
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment