forked from aarronc/hutton-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforward.py
100 lines (85 loc) · 3.11 KB
/
forward.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
"""
Broadcasts to the Hutton Helper web site.
"""
from version import HH_VERSION
import json
import zlib
import plugin
import xmit
ADDITIONAL_PATHS_URL = 'http://hot.forthemug.com/event_paths.json'
def merge_dicts(*dict_args):
"""
Given any number of dicts, shallow copy and merge into a new dict,
precedence goes to key value pairs in latter dicts.
"""
result = {}
for dictionary in dict_args:
result.update(dictionary)
return result
class ForTheMugPlugin(plugin.HuttonHelperPlugin):
"Forwards data to the Hutton Helper Server."
event_paths = {
"Bounty": "/bounty",
"Cargo": "/cargo",
"CargoDepot": "/cargodepot",
"CarrierJump": "/carrierjump",
"CollectCargo": "/cargocollection",
"CommitCrime": "/commitcrime",
"CommunityGoal": "/communitygoal",
"Died": "/death",
"Docked": "/dockedinfoupdate",
"DockingRequested": "/dockingrequested",
"DockingGranted": "/dockinggranted",
"EjectCargo": "/ejectcargo",
"EscapeInterdiction" : "/escapeinterdiction",
"FactionKillBond": "/factionkillbond",
"Friends" : "/friends",
"FSDJump": "/fsdjump",
"FSSAllBodiesFound": "/fssallbodiesfound",
"FSSSignalDiscovered": "/fsssignaldiscovered",
"Interdicted" : "/interdicted",
"Interdiction" : "/interdiction",
"LaunchDrone" : "/launchdrone",
"LoadGame": "/loadgame",
"Loadout": "/loadout",
"MarketBuy": "/buy",
"MarketSell": "/sell",
"MiningRefined": "/miningrefined",
"MissionAbandoned": "/missioncomplete",
"MissionAccepted": "/missiontake",
"MissionCompleted": "/missioncomplete",
"MissionFailed": "/missioncomplete",
"MissionRedirected": "/missionupdate",
"MultiSellExplorationData": "/multisellexplorationdata",
"NpcCrewPaidWage": "/npccrewpaidwage",
"Promotion": "/cmdrpromotion",
"ProspectedAsteroid": "/prospectedasteroid",
"Rank": "/rank",
"ReceiveText": "/receivetext",
"SAAScanComplete": "/saascancomplete",
"SAASignalsFound": "/saasignalsfound",
"Scan": "/scan",
"SearchAndRescue": "/searchandrescue",
"SellExplorationData": "/explorationdata",
"ShipTargeted": "/shiptargeted",
"SquadronStartup": "/squadronstartup",
"StartJump": "/startjump",
"Statistics": "/stats",
"SupercruiseEntry": "/supercruiseentry",
"SupercruiseExit": "/supercruiseexit",
"Undocked": "/undockedinfoupdate",
"USSDrop" : "/ussdrop"
}
def plugin_start(self):
"Called once at startup. Try to keep it short..."
extra_paths = xmit.get(ADDITIONAL_PATHS_URL)
if extra_paths is not None:
self.event_paths = merge_dicts(self.event_paths, extra_paths)
def journal_entry(self, cmdr, is_beta, system, station, entry, state):
"Called when Elite Dangerous writes to the commander's journal."
event = entry['event']
event_path = self.event_paths.get(event)
compress_json = json.dumps(entry)
transmit_json = zlib.compress(compress_json.encode('utf-8'))
if event_path:
xmit.post(event_path, data=transmit_json, parse=False, headers=xmit.COMPRESSED_OCTET_STREAM)