diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 716671c8..0db13ecb 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -731,7 +731,9 @@ class PanelHandler(BaseHandler): server_id, model=True ) ) - page_data["triggers"] = WebhookFactory.get_monitored_events() + page_data["triggers"] = list( + WebhookFactory.get_monitored_events().keys() + ) def get_banned_players_html(): banned_players = self.controller.servers.get_banned_players(server_id) @@ -1041,7 +1043,7 @@ class PanelHandler(BaseHandler): page_data["webhook"]["enabled"] = True page_data["providers"] = WebhookFactory.get_supported_providers() - page_data["triggers"] = WebhookFactory.get_monitored_events() + page_data["triggers"] = list(WebhookFactory.get_monitored_events().keys()) if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]: if not superuser: @@ -1092,7 +1094,7 @@ class PanelHandler(BaseHandler): ).split(",") page_data["providers"] = WebhookFactory.get_supported_providers() - page_data["triggers"] = WebhookFactory.get_monitored_events() + page_data["triggers"] = list(WebhookFactory.get_monitored_events().keys()) if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]: if not superuser: diff --git a/app/classes/web/webhooks/webhook_factory.py b/app/classes/web/webhooks/webhook_factory.py index 9fe2c752..c0fbbede 100644 --- a/app/classes/web/webhooks/webhook_factory.py +++ b/app/classes/web/webhooks/webhook_factory.py @@ -13,7 +13,7 @@ class WebhookFactory: to manage the available providers. Attributes: - - _registry (dict): A dictionary mapping provider names to their classes. + - _registry (dict): A dictionary mapping provider names to their classes. """ _registry = { @@ -32,18 +32,18 @@ class WebhookFactory: provided arguments. If the provider is not recognized, a ValueError is raised. Arguments: - - provider_name (str): The name of the desired webhook provider. + - provider_name (str): The name of the desired webhook provider. Additional arguments supported that we may use for if a provider requires initialization: - - *args: Positional arguments to pass to the provider's constructor. - - **kwargs: Keyword arguments to pass to the provider's constructor. + - *args: Positional arguments to pass to the provider's constructor. + - **kwargs: Keyword arguments to pass to the provider's constructor. Returns: - WebhookProvider: An instance of the desired webhook provider. + WebhookProvider: An instance of the desired webhook provider. Raises: - ValueError: If the specified provider name is not recognized. + ValueError: If the specified provider name is not recognized. """ if provider_name not in cls._registry: raise ValueError(f"Provider {provider_name} is not supported.") @@ -58,7 +58,7 @@ class WebhookFactory: currently registered in the factory's registry. Returns: - List[str]: A list of supported provider names. + List[str]: A list of supported provider names. """ return list(cls._registry.keys()) @@ -68,17 +68,23 @@ class WebhookFactory: Retrieves the list of supported events for monitoring. This method provides a list of common server events that the webhook system can - monitor and notify about. + monitor and notify about. Along with the available `event_data` vars for use + on the frontend. Returns: - List[str]: A list of supported monitored actions. + dict: A dictionary where each key is an event name and the value is a + dictionary containing a list of `variables` for that event. + These variables are intended for use in the frontend to show whats + available. """ - return [ - "start_server", - "stop_server", - "crash_detected", - "backup_server", - "jar_update", - "send_command", - "kill", - ] + return { + "start_server": {"variables": ["server_name", "user", "timestamp"]}, + "stop_server": {"variables": ["server_name", "user", "timestamp"]}, + "crash_detected": {"variables": ["server_name", "user", "timestamp"]}, + "backup_server": {"variables": ["server_name", "user", "timestamp"]}, + "jar_update": {"variables": ["server_name", "user", "timestamp"]}, + "send_command": { + "variables": ["server_name", "user", "command", "timestamp"] + }, + "kill": {"variables": ["server_name", "user", "timestamp"]}, + }