mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Refactor get_monitored_events to dict to incl supported variables
Update panel_handler to account for type change to get_monitored_events
This commit is contained in:
parent
ae4f806bac
commit
915245bbff
@ -731,7 +731,9 @@ class PanelHandler(BaseHandler):
|
|||||||
server_id, model=True
|
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():
|
def get_banned_players_html():
|
||||||
banned_players = self.controller.servers.get_banned_players(server_id)
|
banned_players = self.controller.servers.get_banned_players(server_id)
|
||||||
@ -1041,7 +1043,7 @@ class PanelHandler(BaseHandler):
|
|||||||
page_data["webhook"]["enabled"] = True
|
page_data["webhook"]["enabled"] = True
|
||||||
|
|
||||||
page_data["providers"] = WebhookFactory.get_supported_providers()
|
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 EnumPermissionsServer.CONFIG in page_data["user_permissions"]:
|
||||||
if not superuser:
|
if not superuser:
|
||||||
@ -1092,7 +1094,7 @@ class PanelHandler(BaseHandler):
|
|||||||
).split(",")
|
).split(",")
|
||||||
|
|
||||||
page_data["providers"] = WebhookFactory.get_supported_providers()
|
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 EnumPermissionsServer.CONFIG in page_data["user_permissions"]:
|
||||||
if not superuser:
|
if not superuser:
|
||||||
|
@ -13,7 +13,7 @@ class WebhookFactory:
|
|||||||
to manage the available providers.
|
to manage the available providers.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
- _registry (dict): A dictionary mapping provider names to their classes.
|
- _registry (dict): A dictionary mapping provider names to their classes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_registry = {
|
_registry = {
|
||||||
@ -32,18 +32,18 @@ class WebhookFactory:
|
|||||||
provided arguments. If the provider is not recognized, a ValueError is raised.
|
provided arguments. If the provider is not recognized, a ValueError is raised.
|
||||||
|
|
||||||
Arguments:
|
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
|
Additional arguments supported that we may use for if a provider
|
||||||
requires initialization:
|
requires initialization:
|
||||||
- *args: Positional 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.
|
- **kwargs: Keyword arguments to pass to the provider's constructor.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
WebhookProvider: An instance of the desired webhook provider.
|
WebhookProvider: An instance of the desired webhook provider.
|
||||||
|
|
||||||
Raises:
|
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:
|
if provider_name not in cls._registry:
|
||||||
raise ValueError(f"Provider {provider_name} is not supported.")
|
raise ValueError(f"Provider {provider_name} is not supported.")
|
||||||
@ -58,7 +58,7 @@ class WebhookFactory:
|
|||||||
currently registered in the factory's registry.
|
currently registered in the factory's registry.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List[str]: A list of supported provider names.
|
List[str]: A list of supported provider names.
|
||||||
"""
|
"""
|
||||||
return list(cls._registry.keys())
|
return list(cls._registry.keys())
|
||||||
|
|
||||||
@ -68,17 +68,23 @@ class WebhookFactory:
|
|||||||
Retrieves the list of supported events for monitoring.
|
Retrieves the list of supported events for monitoring.
|
||||||
|
|
||||||
This method provides a list of common server events that the webhook system can
|
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:
|
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 [
|
return {
|
||||||
"start_server",
|
"start_server": {"variables": ["server_name", "user", "timestamp"]},
|
||||||
"stop_server",
|
"stop_server": {"variables": ["server_name", "user", "timestamp"]},
|
||||||
"crash_detected",
|
"crash_detected": {"variables": ["server_name", "user", "timestamp"]},
|
||||||
"backup_server",
|
"backup_server": {"variables": ["server_name", "user", "timestamp"]},
|
||||||
"jar_update",
|
"jar_update": {"variables": ["server_name", "user", "timestamp"]},
|
||||||
"send_command",
|
"send_command": {
|
||||||
"kill",
|
"variables": ["server_name", "user", "command", "timestamp"]
|
||||||
]
|
},
|
||||||
|
"kill": {"variables": ["server_name", "user", "timestamp"]},
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user