Skip to content

Commit 633a19b

Browse files
Sebastian De RoNick Woodward
Sebastian De Ro
authored and
Nick Woodward
committed
Command: what is my name? whats my name? what's my name? (#50)
1 parent dc47eb1 commit 633a19b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/auth.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# hubot what roles do I have - Find out what roles you have
1212
# hubot who has <role> role - Find out who has the given role
1313
# 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
1416
#
1517
# Notes:
1618
# * Call the method: robot.auth.hasRole(msg.envelope.user,'<role>')
@@ -144,3 +146,17 @@ module.exports = (robot) ->
144146
msg.reply "The following roles are available: #{roles.join(', ')}"
145147
else
146148
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']}."

test/auth-test.coffee

+17-1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,20 @@ describe "auth", ->
144144
["hubot", "@alice OK, jimmy jones has the 'demo' role."]
145145
["amy", "hubot: what roles does jimmy jones have?"]
146146
["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+
]

0 commit comments

Comments
 (0)