-
Notifications
You must be signed in to change notification settings - Fork 3
/
cast-party-spells-with-equip.py
executable file
·120 lines (105 loc) · 4.52 KB
/
cast-party-spells-with-equip.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
import argparse
import os
import re
import sys
import requests
def unequip(gear):
for _, v in gear.items():
# If item ~ "base_0", you are already unequipped, so skip
if "base_0" not in v:
requests.post(args.baseurl + f'user/equip/equipped/{v}', headers=headers, timeout=10)
# MAIN
parser = argparse.ArgumentParser(description="Template for equipping a special set of armor \
to improve stats before casting party spells during a quest",
epilog="See https://habitica.com/apidoc/#api-User-UserCast for the key map of class spells")
parser.add_argument('-c', '--cast',
required=True,
choices=['all', 'both', 'none', 'blessing', 'healAll', 'protect', 'protectAura', 'protectiveaura'],
help='Spell(s) to cast')
parser.add_argument('-b', '--bossquest',
action='store_true',
help='Equip a special equipment set for fighting bosses')
parser.add_argument('-u', '--user-id',
help='From https://habitica.com/#/options/settings/api\n \
default: environment variable HAB_API_USER')
parser.add_argument('-k', '--api-token',
help='From https://habitica.com/#/options/settings/api\n \
default: environment variable HAB_API_TOKEN')
parser.add_argument('--baseurl',
type=str, default="https://habitica.com",
help='API server (default: https://habitica.com)')
if len(sys.argv) == 1:
parser.print_help()
sys.exit()
args = parser.parse_args()
args.baseurl += "/api/v3/"
try:
if args.user_id is None:
args.user_id = os.environ['HAB_API_USER']
if not re.match(r'^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$', args.user_id, re.IGNORECASE):
print(f"Invalid User ID: '{args.user_id}'")
sys.exit(1)
except KeyError:
print("User ID must be set by the -u/--user-id option or by setting the environment variable 'HAB_API_USER'")
sys.exit(1)
try:
if args.api_token is None:
args.api_token = os.environ['HAB_API_TOKEN']
if not re.match(r'^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$', args.api_token, re.IGNORECASE):
print(f"Invalid API Token: '{args.api_token}'")
sys.exit(1)
except KeyError:
print("API Token must be set by the -k/--api-token option or by setting the environment variable 'HAB_API_TOKEN'")
sys.exit(1)
headers = {"x-api-user": args.user_id, "x-api-key": args.api_token, "Content-Type": "application/json"}
# Max out Constitution
aura = {
"armor": "armor_healer_5",
"head": "head_armoire_orangeCat",
"shield": "shield_special_goldenknight",
"weapon": "weapon_armoire_blueLongbow"
}
# Max out Constitution and Intelligence
blessing = {
"armor": "armor_special_2",
"head": "head_special_2",
"shield": "shield_special_goldenknight",
"weapon": "weapon_healer_6"
}
# Max out Strength
bossquest = {
"armor": "armor_special_finnedOceanicArmor",
"head": "head_special_2",
"shield": "shield_armoire_perchingFalcon",
"weapon": "weapon_special_2"
}
# Max out all attributes
quest = {
"armor": "armor_special_2",
"head": "head_special_2",
"shield": "shield_special_goldenknight",
"weapon": "weapon_special_2"
}
# If bossquest, then set questing equipment set to that
if args.bossquest:
quest = bossquest
# First record what you're already wearing
req = requests.get(args.baseurl + "user", headers=headers, timeout=10)
# If you "equip" what you're already wearing, you unequip it
unequip(req.json()['data']['items']['gear']['equipped'])
# Protective Aura
if args.cast in ("all", "both", "protect", "protectAura", "protectiveaura"):
for _, v in aura.items():
req = requests.post(args.baseurl + f'user/equip/equipped/{v}', headers=headers, timeout=10)
spell = requests.post(args.baseurl + "user/class/cast/protectAura", headers=headers, timeout=10)
unequip(req.json()['data']['gear']['equipped'])
# Blessing
if args.cast in ("all", "both", "blessing", "healAll"):
for _, v in blessing.items():
req = requests.post(args.baseurl + f'user/equip/equipped/{v}', headers=headers, timeout=10)
spell = requests.post(args.baseurl + "user/class/cast/healAll", headers=headers, timeout=10)
unequip(req.json()['data']['gear']['equipped'])
# Equip for quest
for _, v in quest.items():
req = requests.post(args.baseurl + f'user/equip/equipped/{v}', headers=headers, timeout=10)