This repository has been archived by the owner on Oct 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omniinara.py
210 lines (182 loc) · 4.81 KB
/
omniinara.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
"""
Inara parsers
"""
import omniutils as ou
gui_ranks = [
'combat',
'trade',
'exploration'
]
gui_wing = [
'wingMemberRank',
'wingName'
]
base_labels = {
'preferredAllegianceName': 'Allegiance',
'preferredPowerName': 'Power'
}
wing_labels = {
'wingName': 'Wing',
'wingMemberRank': 'Rank'
}
rank_values = {
'combat': {
0: 'Harmless',
1: 'Mostly Harmless',
2: 'Novice',
3: 'Competent',
4: 'Expert',
5: 'Master',
6: 'Dangerous',
7: 'Deadly',
8: 'Elite',
},
'trade': {
0: 'Penniless',
1: 'Mostly Penniless',
2: 'Peddler',
3: 'Dealer',
4: 'Merchant',
5: 'Broker',
6: 'Entrepreneur',
7: 'Tycoon',
8: 'Elite',
},
'exploration': {
0: 'Aimless',
1: 'Mostly Aimless',
2: 'Scout',
3: 'Surveyor',
4: 'Trailblazer',
5: 'Pathfinder',
6: 'Ranger',
7: 'Pioneer',
8: 'Elite',
},
'cqc': {
0: 'Helpless',
1: 'Mostly Helpless',
2: 'Amateur',
3: 'Semi Professional',
4: 'Professional',
5: 'Champion',
6: 'Hero',
7: 'Legend',
8: 'Elite',
},
'empire': {
0: 'None',
1: 'Outsider',
2: 'Serf',
3: 'Master',
4: 'Squire',
5: 'Knight',
6: 'Lord',
7: 'Baron',
8: 'Viscount',
9: 'Count',
10: 'Earl',
11: 'Marquis',
12: 'Duke',
13: 'Prince',
14: 'King'
},
'federation': {
0: 'None',
1: 'Recruit',
2: 'Cadet',
3: 'Midshipman',
4: 'Petty Officer',
5: 'Chief Petty Officer',
6: 'Warrant Officer',
7: 'Ensign',
8: 'Lieutenant',
9: 'Lt Commander',
10: 'Post Commander',
11: 'Post Captain',
12: 'Rear Admiral',
13: 'Vice Admiral',
14: 'Admiral'
}
}
def is_good_response(reply):
"""
Check if the Inara response is solid
:param reply:
:return:
"""
events = reply['events']
if events[0]['eventStatus'] != 204:
if 'otherNamesFound' in events[0]['eventData']:
ou.notify("Ugh multiple results on Inara...")
return False
return True
return False
def parse_reply_for_gui(reply):
"""
Parse Inara reply for the GUI
:param reply:
:return:
"""
parsed_data = None
if is_good_response(reply):
eventData = reply['events'][0]['eventData']
parsed_data = []
# give role a custom key
if 'preferredGameRole' in eventData:
if eventData['preferredGameRole']:
parsed_data.append({
'text': eventData['preferredGameRole'],
})
for rank in eventData['commanderRanksPilot']:
if rank['rankName'] in gui_ranks:
rank_name = rank['rankName']
rank_val = rank_values[rank_name][rank['rankValue']]
parsed_data.append({
'text': rank_val,
'tag': rank_name,
'len': len(rank_val)
})
for label in base_labels:
if label in eventData:
if eventData[label]:
parsed_data.append({
'text': u"{}: {}".format(base_labels[label], eventData[label]),
})
# Wing data is not always present
if 'commanderWing' in eventData:
wingData = eventData['commanderWing']
parsed_data.append({
'text': u" of ".join([wingData[label] for label in gui_wing]),
})
return parsed_data
def parse_reply_for_overlay(reply):
"""
Parse Inara reply for the Overlay
:param reply:
:return:
"""
line_template = u"{}: {}"
cmdrData = None
if is_good_response(reply):
eventData = reply['events'][0]['eventData']
cmdrData = {}
# give role a custom key
if 'preferredGameRole' in eventData:
cmdrData['role'] = eventData['preferredGameRole']
cmdrData['base'] = [
line_template.format(base_labels[label], eventData[label])
for label in base_labels if label in eventData
]
cmdrData['rank'] = [
line_template.format(rank['rankName'], rank_values[rank['rankName']][rank['rankValue']])
for rank in eventData['commanderRanksPilot']
]
# Wing data is not always present
if 'commanderWing' in eventData:
wingData = eventData['commanderWing']
cmdrData['wing'] = [
line_template.format(wing_labels[label], wingData[label])
for label in wing_labels
]
return cmdrData