1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | images = require './data/highfivegifs.json'
|
21 |
|
22 | module.exports = (robot) ->
|
23 | robot.respond /high five ([^ ]*)( (.*))?/i, (msg) ->
|
24 | if praiseUser(msg)
|
25 | updatePraises(msg, robot)
|
26 | robot.respond /praise ([^ ]*)( (.*))?/i, (msg) ->
|
27 | if praiseUser(msg)
|
28 | updatePraises(msg, robot)
|
29 | robot.respond /who praised/i, (msg) ->
|
30 | getPraises(msg, robot)
|
31 |
|
32 |
|
33 | praiseUser = (msg) ->
|
34 | user = msg.match[1].replace(/@?(.*)/, '$1')
|
35 | message = msg.match[3]
|
36 | current_user = msg.message.user.name
|
37 | if user == current_user
|
38 | msg.send "you can’t high five yourself. that’s just clapping"
|
39 | return false
|
40 | else
|
41 | highfive = msg.random images
|
42 | praise = msg.random praises(user)
|
43 | msg.send highfive
|
44 | msg.send "@#{current_user} high fives @#{user}.#{if message then " #{message}" else ""}"
|
45 | msg.send praise
|
46 | return true
|
47 |
|
48 | praises = (user) ->
|
49 | return [
|
50 | "Keep on rocking, @#{user}!",
|
51 | "Keep up the great work, @#{user}!",
|
52 | "You're awesome, @#{user}!",
|
53 | "You're doing good work, @#{user}!",
|
54 | "You're the best, @#{user}",
|
55 | "Never stop doing what you do @#{user}, it's paying off!",
|
56 | "Thanks so much, you've been amazing @#{user}!",
|
57 | "How many people does it take to change a lightbulb? Nvm @#{user} changed 100 before you even responded!",
|
58 | "Your work is phenomenal, @#{user}!",
|
59 | "You are changing lives with your work, @#{user}!",
|
60 | "The world is a better place with you around, @#{user}",
|
61 | "Is there anything you can't do @#{user}? Wow!"
|
62 | ]
|
63 |
|
64 | updatePraises = (msg, robot) ->
|
65 | currentPraises = robot.brain.get('praises')
|
66 | today = new Date().toLocaleString()
|
67 |
|
68 | if currentPraises.length <= 0
|
69 | currentPraises = []
|
70 |
|
71 | currentPraises.push(
|
72 | {
|
73 | receiver: msg.match[1],
|
74 | sender: msg.message.user.name,
|
75 | message: msg.match[3],
|
76 | date: today
|
77 | }
|
78 | )
|
79 |
|
80 | robot.brain.set('praises', currentPraises)
|
81 |
|
82 | getPraises = (msg, robot) ->
|
83 | msg.send "ALL PRAISES EVER"
|
84 | message = ""
|
85 | allPraises = robot.brain.get('praises')
|
86 | if allPraises
|
87 | for praise in allPraises
|
88 | message = "@#{praise.sender} sent a praise for #{if praise.message then " #{praise.message}" else "awesomeness"} to @#{praise.receiver} on #{praise.date} \n\r";
|
89 | msg.send message
|
90 | else
|
91 | msg.send "none"
|