This repository has been archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Main.gs
59 lines (42 loc) · 1.63 KB
/
Main.gs
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
// Globals
const scriptProperties = PropertiesService.getScriptProperties();
function main() {
// Initialize the data
getGTasks();
getTodosFromHabitica();
// Get tasks from GTasks
let [gtasksCompletedIDs, gtasksIncompleteIDs] = getGTasksId();
// Get todos from Habitica. This entire list only contains incomplete tasks
let habiticaTodoAliases = getHabiticaTodoAliases();
// Copy incomplete tasks from GTasks to Habitica
// If the GTask ID is not in the list of Habitica aliases
// Add it to Habitica
let incompleteGTaskIDsToCopy = gtasksIncompleteIDs.filter(x => !habiticaTodoAliases.includes(x));
for(let t of incompleteGTaskIDsToCopy){
addGTaskToHabitica(t);
}
// Mark all completed tasks as done
let completeGTaskIDsToMarkAsDone = gtasksCompletedIDs.filter(x => habiticaTodoAliases.includes(x));
for(let t of completeGTaskIDsToMarkAsDone){
markGTaskAsDone(t);
}
// Update changes in due date
// Find GTasks that are in Habitica
let incompleteGTaskIDsInHabitica = gtasksIncompleteIDs.filter(x => habiticaTodoAliases.includes(x));
// Find any mismatch in due dates
for (let t of incompleteGTaskIDsInHabitica){
let habiticaTodo = getHabiticaTodoFromAlias(t);
let gtask = getGTaskFromId(t);
if (gtask.dueDate === undefined){
// pass
} else {
let gtaskDueDate = new Date(gtask.dueDate);
let habiticaDueDate = new Date(habiticaTodo.dueDate);
if (gtaskDueDate.valueOf() === habiticaDueDate.valueOf()){
// pass
} else {
buildRequest("put", "tasks/" + habiticaTodo.id, {"date": gtask.dueDate});
}
}
}
}