-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththankfulness.coffee
46 lines (35 loc) · 1.07 KB
/
thankfulness.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
# Description
# A Hubot script that listens for thanks yous
#
# Configuration:
# HUBOT_THANKS_URL - URL to remind thanker to visit
#
# Commands:
# (thanks|thank you) @user for being awesome - bot DMs you with a thank you reminder
#
# Author:
# Andy Chosak
module.exports = (robot) ->
thanksKeywords = "thanks|thank you"
robot.hear ///
(?:#{thanksKeywords})
\s+
([\w"@.\-:]+)(?:[,!.])?
\s*
(.+)?
///i, (res) ->
[dummy, username, message] = res.match
username = username.replace(/^@+/, "")
user = robot.brain.userForName(username)
return unless user?
email = encodeURIComponent(user.email_address)
baseUrl = process.env.HUBOT_THANKS_URL
unless baseUrl?
res.reply "Missing HUBOT_THANKS_URL in environment. Please set and try again."
return
url = "#{baseUrl}?email=#{email}"
if message?
draft_thanks = encodeURIComponent(message)
url += "&draft_thanks=#{draft_thanks}"
message = "To thank @#{username}, visit this URL: #{url}"
robot.messageRoom res.message.user.name, message