-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhabitica.js
41 lines (35 loc) · 989 Bytes
/
habitica.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
var Habitica = require('habitica');
var log = require('debug-logger')('hacktheplanet');
var habitica = module.exports = {};
habitica.init = function() {
// Make sure we have habitica keys
if (process.env.HABITICA_ID && process.env.HABITICA_TOKEN) {
habitica.api = new Habitica({
uuid: process.env.HABITICA_ID,
token: process.env.HABITICA_TOKEN
});
log.debug('')
}
else
log.error('You must have HABITICA_ID and HABITICA_TOKEN in your env');
};
/**
* Add a task to your habitica account
* @param {Object} task The task to add of the form
*/
habitica.addTasks = function(tasks, callback) {
if (!habitica.api) {
log.error('You tried to do a bad thing and you should feel bad');
return;
}
function add(task, i) {
habitica.api.task
.post(task)
.then(function(response) {
log.debug('Task add response: ', response);
i++;
if (i < tasks.length) add(tasks[i], i);
});
}
add(tasks[0], 0);
}