-
Notifications
You must be signed in to change notification settings - Fork 0
/
habitica_utilities.sh
executable file
·55 lines (47 loc) · 1.2 KB
/
habitica_utilities.sh
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
#!/usr/bin/env bash
authorId="8b819da9-81e7-42e4-992e-cd1a9c3a823b"
baseUrl="https://habitica.com/api/v3"
makeRequest() {
if [ "$2" == "GET" ]
then
curl "${baseUrl}/${1}" -s -X GET --compressed \
-H "Content-Type: application/json" \
-H "x-api-user: ${HABIT_ID}" \
-H "x-api-key: ${HABIT_KEY}" \
-H "x-client: ${authorID}"
fi
if [ "$2" == "POST" ] && [ -z "$3" ]
then
curl "${baseUrl}/${1}" -s -X POST \
-H "Content-length: 0" \
-H "Content-Type: application/json" \
-H "x-api-user: ${HABIT_ID}" \
-H "x-api-key: ${HABIT_KEY}" \
-H "x-client: ${authorID}"
fi
}
checkQuest() {
details=$(makeRequest "groups/party" "GET")
status=$(echo "$details" | jq .data.quest.key)
active=$(echo "$details" | jq .data.quest.active)
if [ "$active" == "true" ] && [ -n "$status" ]
then
echo "No new quests"
exit
else
acceptQuest
fi
}
acceptQuest(){
makeRequest "groups/party/quests/accept" "POST"
}
cronTrigger(){
makeRequest "cron" "POST"
}
if [ "$1" == 'quest' ]
then
checkQuest
elif [ "$1" == 'cron' ]
then
cronTrigger
fi