Skip to content

Commit 4297154

Browse files
quickjp2Nick Woodward
authored and
Nick Woodward
committed
docs(readme): add sample usage within a script (#54)
1 parent d1c5515 commit 4297154

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,28 @@ Run `npm install`
2828
user1>> hubot user2 has jester role
2929
hubot>> OK, user2 has the jester role.
3030
```
31+
32+
## Sample Usage
33+
### Restricting commands
34+
```coffee
35+
module.exports = (robot) ->
36+
# Command listener
37+
robot.respond /some command/i, (msg) ->
38+
role = 'some-role'
39+
user = robot.brain.userForName(msg.message.user.name)
40+
return msg.reply "#{name} does not exist" unless user?
41+
unless robot.auth.hasRole(user, role)
42+
msg.reply "Access Denied. You need role #{role} to perform this action."
43+
return
44+
# Some commandy stuff
45+
msg.reply 'Command done!'
46+
```
47+
### Example Interaction
48+
```
49+
user2>> hubot some command
50+
hubot>> Access Denied. You need role some-role to perform this action.
51+
user1>> hubot user2 has some-role role
52+
hubot>> OK, user2 has the some-role role.
53+
user2>> hubot some command
54+
hubot>> Command done!
55+
```

0 commit comments

Comments
 (0)