From 6374fbbeb86272a5e5e89d700acf8d35778c35b6 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 29 Oct 2020 14:44:32 +0200 Subject: [PATCH] Added event disabling You can now disable specific event handlers in plugins --- docs/Killswitches.md | 15 ++++++--------- plugins/eddb.py | 3 +++ plugins/eddn.py | 3 +++ plugins/edsm.py | 9 ++++++--- plugins/inara.py | 7 ++++--- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index d9b5930c..8603d10d 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -48,12 +48,9 @@ be used to query the kill switch set, see the docstrings for more information on ## Currently supported killswitch strings The current recognised (to EDMC and its internal plugins) killswitch strings are as follows: -| Kill Switch | Description | -| :---------------------- | :---------------------------------------------------------------------------------------- | -| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | -| `plugins.eddn.journal` | Disables all journal processing for EDDN | -| `plugins.edsm.worker` | Disables the send portion of the EDSM worker thread (effectively disables EDSM updates) | -| `plugins.edsm.journal` | Disables all journal processing for EDSM | -| `plugins.inara.worker` | Disables the send portion of the INARA worker thread (effectively disables INARA updates) | -| `plugins.inara.journal` | Disables all journal processing for INARA | -| `plugins.eddn.journal` | Disables all journal processing for EDDN | +| Kill Switch | Description | +| :--------------------------------------------------- | :------------------------------------------------------------------------------------------- | +| `plugins.eddn.send` | Disables all use of the send method on EDDN (effectively disables EDDN updates) | +| `plugins.(eddn|inara|edsm|eddb).journal` | Disables all journal processing for EDDN/EDSM/INARA | +| `plugins.(edsm|inara).worker` | Disables the EDSM/INARA worker thread (effectively disables updates) (does not close thread) | +| `plugins.(eddn|inara|edsm).journal.event.$eventname` | Specific events to disable processing for | diff --git a/plugins/eddb.py b/plugins/eddb.py index bd6b154f..1886b410 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -97,6 +97,9 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): logger.warning(f'Journal processing for EDDB has been disabled: {ks.reason}') plug.show_error('EDDB Journal processing disabled. See Log') return + elif (ks := killswitch.get_disabled(f'plugins.eddb.journal.event.{entry["event"]}')).disabled: + logger.warning(f'Processing of event {entry["event"]} has been disabled: {ks.reason}') + return # Always update our system address even if we're not currently the provider for system or station, but dont update # on events that contain "future" data, such as FSDTarget diff --git a/plugins/eddn.py b/plugins/eddn.py index eac1b0d3..61624246 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -614,6 +614,9 @@ def journal_entry( # noqa: C901 logger.warning(f"EDDN journal handler has been disabled via killswitch: {ks.reason}") plug.show_error("EDDN journal handler disabled. See Log.") return + elif (ks := killswitch.get_disabled(f'plugins.eddn.journal.event{entry["name"]}')).disabled: + logger.warning(f'Handling of event {entry["name"]} disabled via killswitch: {ks.reason}') + return # Recursively filter '*_Localised' keys from dict def filter_localised(d: Mapping[str, Any]) -> OrderedDictT[str, Any]: diff --git a/plugins/edsm.py b/plugins/edsm.py index 970b26f2..f3f8479e 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -339,9 +339,12 @@ def journal_entry( cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any] ) -> None: """Journal Entry hook.""" - if (ks := killswitch.get_disabled("plugins.edsm.journal")).disabled: - logger.warning(f"EDSM Journal handler disabled via killswitch: {ks.reason}") - plug.show_error("EDSM Handler disabled. See Log.") + if (ks := killswitch.get_disabled('plugins.edsm.journal')).disabled: + logger.warning(f'EDSM Journal handler disabled via killswitch: {ks.reason}') + plug.show_error('EDSM Handler disabled. See Log.') + return + elif (ks := killswitch.get_disabled(f'plugins.edsm.journal.event.{entry["name"]}')).disabled: + logger.warning(f'Handling of event {entry["name"]} has been disabled via killswitch: {ks.reason}') return if entry['event'] in ('CarrierJump', 'FSDJump', 'Location', 'Docked'): diff --git a/plugins/inara.py b/plugins/inara.py index 729e4b9e..f48a9d31 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -322,10 +322,11 @@ def journal_entry( cmdr: str, is_beta: bool, system: str, station: str, entry: Dict[str, Any], state: Dict[str, Any] ) -> None: """Journal entry hook.""" - if (ks := killswitch.get_disabled("plugins.inara.journal")).disabled: - logger.warning(f"INARA support has been disabled via killswitch: {ks.reason}") - plug.show_error("INARA disabled. See Log.") + if (ks := killswitch.get_disabled('plugins.inara.journal')).disabled: + logger.warning(f'INARA support has been disabled via killswitch: {ks.reason}') + plug.show_error('INARA disabled. See Log.') return + elif (ks := killswitch.get_disabled(f'')) event_name: str = entry['event'] this.cmdr = cmdr