-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-reward.js
96 lines (83 loc) · 2.2 KB
/
generate-reward.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
/**
* Serve resources from a CDN rather than the same host, to reduce strain
* on the heroku.
*/
const cdn = 'https://cdn.rawgit.com/harrymt/harryshabits/e7fea8e6/public';
/**
* Visual rewards.
*/
const visualRewards = [
'https://media.giphy.com/media/XreQmk7ETCak0/giphy.gif', // Boy at computer, thumbs up
'https://media.giphy.com/media/XreQmk7ETCak0/giphy.gif', // Gameshow host celebrating
'https://media.giphy.com/media/oGO1MPNUVbbk4/giphy.gif', // Small boy thumbs up
'https://media.giphy.com/media/uudzUtVcsLAoo/giphy.gif' // Baseballer fist success
];
/**
* Auditory rewards.
*/
const audioMP3 = [
'/sound/hands-up.mp3',
'/sound/snow.mp3',
'/sound/thumbs-up.mp3',
'/sound/base-ball.mp3',
'/sound/we-are-the-campions.mp3'
];
/**
* Inline auditory rewards.
*/
const audioSpotify = [
'https://open.spotify.com/track/2olVm1lHicpveMAo4AUDRB', // Power of love
'https://open.spotify.com/track/3fthfkkvy9av3q3uAGVf7U', // Shake it off
'https://open.spotify.com/track/6Nf1bklus7o9fpKto13nDc', // OK GO, this shall not pass
'https://open.spotify.com/track/6Lphpr9Z6H282Sguw0dUWa' // Ahh Freak out
];
/**
* Visual-Auditory rewards.
*/
const audioVisualRewards = [
'hands-up',
'snow',
'we-are-the-campions',
'thumbs-up',
'base-ball'
];
/**
* Wrap a random visualm reward, wrapped up in an object.
*/
const getVisualReward = (online) => {
if (online) {
return getRandom(visualRewards);
}
return cdn + '/gif/' + getRandom(audioVisualRewards) + '.gif';
};
/**
* Choose a random auditory reward and wrap it up into an object ready to send.
*/
const getAudioReward = (spotifyRewards) => {
if (spotifyRewards) {
return getRandom(audioSpotify);
}
return cdn + getRandom(audioMP3);
};
/**
* Get a visual-auditory reward.
*/
const getVisualAudioReward = () => {
const reward = getRandom(audioVisualRewards);
return {
audio: cdn + '/sound/' + reward + '.mp3',
gif: cdn + '/gif/' + reward + '.gif'
};
};
/**
* Get a random number that is within the bounds of the array (arr).
*/
function getRandom(arr) {
return arr[Math.floor((Math.random() * (arr.length)) + 1) - 1];
}
module.exports = {
getVisualReward,
getVisualAudioReward,
getAudioReward
};