-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavailability.coffee
executable file
·75 lines (64 loc) · 2.24 KB
/
availability.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Description:
# Set your availability status so people know whether they're able to come
# over and chat with you or ping you over IM.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot is <user> available - Find out if the specified user is available or not
# hubot i am <available|free|not busy|at hand> - Set that you are available
# hubot i am <unavailable|dnd|do not disturb|busy|in the zone> - Setthat you are not available
#
# Author:
# tombell
module.exports = (robot) ->
# Find the user by user name from hubot's brain.
#
# name - A full or partial name match.
#
# Returns a user object if a single user is found, an array of users if more
# than one user matched the name or false if no user is found.
findUser = (name) ->
users = robot.brain.usersForFuzzyName name
if users.length is 1
users[0]
else if users.length > 1
users
else
false
robot.respond /is (.*) available(\?)?/i, (msg) ->
name = msg.match[1]
user = findUser name
if typeof user is 'object'
if user.available.available
msg.send "#{user.name} has been available since #{user.available.timestamp}"
else
msg.send "#{user.name} has been unavailable since #{user.available.timestamp}"
else if typeof user.length > 1
msg.send "I found #{user.length} people named #{name}"
else
msg.send "I have never met #{name}"
robot.respond /i am (available|free|not busy|at hand)/i, (msg) ->
name = msg.message.user.name
user = findUser name
if typeof user is 'object'
user.available = available: true, timestamp: new Date
msg.reply "Okay, I have set you as available"
else if typeof user.length > 1
msg.send "I found #{user.length} people named #{name}"
else
msg.send "I have never met #{name}"
robot.respond /i am (unavailable|dnd|do not disturb|busy|in the zone)/i, (msg) ->
name = msg.message.user.name
user = findUser name
if typeof user is 'object'
user.available = available: false, timestamp: new Date
msg.reply "Okay, I have set you as unavailable"
else if typeof user.length > 1
msg.send "I found #{user.length} people named #{name}"
else
msg.send "I have never met #{name}"