Commit 633a19b 1 parent dc47eb1 commit 633a19b Copy full SHA for 633a19b
File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11
11
# hubot what roles do I have - Find out what roles you have
12
12
# hubot who has <role> role - Find out who has the given role
13
13
# hubot list assigned roles - List all assigned roles
14
+ # hubot what is my name - Tells you your name from persistent storage
15
+ # hubot what is my id - tells you your id from persistent storage
14
16
#
15
17
# Notes:
16
18
# * Call the method: robot.auth.hasRole(msg.envelope.user,'<role>')
@@ -144,3 +146,17 @@ module.exports = (robot) ->
144
146
msg .reply " The following roles are available: #{ roles .join (' , ' )} "
145
147
else
146
148
msg .reply " No roles to list."
149
+
150
+ robot .respond / what(?:'s| s| \s + is)\s + my\s + name\s * (?:\? | )/ i , (msg ) ->
151
+ user = robot .brain .userForId (msg .envelope .user [' id' ])
152
+ unless user and user[' name' ]
153
+ msg .reply " Your user could not be found in my Brain, sorry!"
154
+ return
155
+ msg .reply " Your name is: #{ user[' name' ]} ."
156
+
157
+ robot .respond / what(?:'s| s| \s + is)\s + my\s + id\s * (?:\? | )/ i , (msg ) ->
158
+ user = robot .brain .userForId (msg .envelope .user [' id' ])
159
+ unless user and user[' id' ]
160
+ msg .reply " Your user could not be found in my Brain, sorry!"
161
+ return
162
+ msg .reply " Your ID is: #{ user[' id' ]} ."
Original file line number Diff line number Diff line change @@ -144,4 +144,20 @@ describe "auth", ->
144
144
[" hubot" , " @alice OK, jimmy jones has the 'demo' role." ]
145
145
[" amy" , " hubot: what roles does jimmy jones have?" ]
146
146
[" hubot" , " @amy jimmy jones has the following roles: demo." ]
147
- ]
147
+ ]
148
+
149
+ context " what is my name" , ->
150
+ it " returns the name" , ->
151
+ @room .user .say (" alice" , " hubot: what is my name?" ).then =>
152
+ expect (@room .messages ).to .eql [
153
+ [" alice" , " hubot: what is my name?" ],
154
+ [" hubot" , " @alice Your name is: alice." ]
155
+ ]
156
+
157
+ context " what is my id" , ->
158
+ it " returns the id" , ->
159
+ @room .user .say (" alice" , " hubot: what is my id?" ).then =>
160
+ expect (@room .messages ).to .eql [
161
+ [" alice" , " hubot: what is my id?" ],
162
+ [" hubot" , " @alice Your ID is: alice." ]
163
+ ]
You can’t perform that action at this time.
0 commit comments