From 2d6dae3fc980fab16febac28ae77a7b22bff32fb Mon Sep 17 00:00:00 2001 From: AoXuan Date: Sat, 27 Sep 2025 16:32:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor(config):=20=E9=87=8D=E6=9E=84=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E9=85=8D=E7=BD=AE=E9=A1=B9=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?Webhook=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 19 +++---------------- app/services/notification.py | 5 ++++- app/task/MAA.py | 15 ++++++++++++--- app/task/general.py | 10 ++++++++-- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 472a331..0d19ac8 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -105,10 +105,7 @@ class GlobalConfig(ConfigBase): Notify_ToAddress = ConfigItem("Notify", "ToAddress", "") Notify_IfServerChan = ConfigItem("Notify", "IfServerChan", False, BoolValidator()) Notify_ServerChanKey = ConfigItem("Notify", "ServerChanKey", "") - Notify_IfCompanyWebHookBot = ConfigItem( - "Notify", "IfCompanyWebHookBot", False, BoolValidator() - ) - Notify_CompanyWebHookBotUrl = ConfigItem("Notify", "CompanyWebHookBotUrl", "") + Notify_CustomWebhooks = ConfigItem("Notify", "CustomWebhooks", []) Update_IfAutoUpdate = ConfigItem("Update", "IfAutoUpdate", False, BoolValidator()) Update_Source = ConfigItem( @@ -348,12 +345,7 @@ class MaaUserConfig(ConfigBase): "Notify", "IfServerChan", False, BoolValidator() ) self.Notify_ServerChanKey = ConfigItem("Notify", "ServerChanKey", "") - self.Notify_IfCompanyWebHookBot = ConfigItem( - "Notify", "IfCompanyWebHookBot", False, BoolValidator() - ) - self.Notify_CompanyWebHookBotUrl = ConfigItem( - "Notify", "CompanyWebHookBotUrl", "" - ) + self.Notify_CustomWebhooks = ConfigItem("Notify", "CustomWebhooks", []) def get_plan_info(self) -> Dict[str, Union[str, int]]: """获取当前的计划下信息""" @@ -541,12 +533,7 @@ class GeneralUserConfig(ConfigBase): "Notify", "IfServerChan", False, BoolValidator() ) self.Notify_ServerChanKey = ConfigItem("Notify", "ServerChanKey", "") - self.Notify_IfCompanyWebHookBot = ConfigItem( - "Notify", "IfCompanyWebHookBot", False, BoolValidator() - ) - self.Notify_CompanyWebHookBotUrl = ConfigItem( - "Notify", "CompanyWebHookBotUrl", "" - ) + self.Notify_CustomWebhooks = ConfigItem("Notify", "CustomWebhooks", []) class GeneralConfig(ConfigBase): diff --git a/app/services/notification.py b/app/services/notification.py index 4b580fe..9c1ddb0 100644 --- a/app/services/notification.py +++ b/app/services/notification.py @@ -357,7 +357,10 @@ class Notification: ) # 发送自定义Webhook通知 - custom_webhooks = Config.get("Notify", "CustomWebhooks", []) + try: + custom_webhooks = Config.get("Notify", "CustomWebhooks") + except AttributeError: + custom_webhooks = [] if custom_webhooks: for webhook in custom_webhooks: if webhook.get("enabled", True): diff --git a/app/task/MAA.py b/app/task/MAA.py index 6580f4a..80e9d21 100644 --- a/app/task/MAA.py +++ b/app/task/MAA.py @@ -1907,7 +1907,10 @@ class MaaManager: ) # 发送自定义Webhook通知 - custom_webhooks = Config.get("Notify", "CustomWebhooks", []) + try: + custom_webhooks = Config.get("Notify", "CustomWebhooks") + except AttributeError: + custom_webhooks = [] if custom_webhooks: for webhook in custom_webhooks: if webhook.get("enabled", True): @@ -1970,7 +1973,10 @@ class MaaManager: ) # 发送自定义Webhook通知 - custom_webhooks = Config.get("Notify", "CustomWebhooks", []) + try: + custom_webhooks = Config.get("Notify", "CustomWebhooks") + except AttributeError: + custom_webhooks = [] if custom_webhooks: for webhook in custom_webhooks: if webhook.get("enabled", True): @@ -2055,7 +2061,10 @@ class MaaManager: ) # 发送自定义Webhook通知(六星喜报) - custom_webhooks = Config.get("Notify", "CustomWebhooks", []) + try: + custom_webhooks = Config.get("Notify", "CustomWebhooks") + except AttributeError: + custom_webhooks = [] if custom_webhooks: for webhook in custom_webhooks: if webhook.get("enabled", True): diff --git a/app/task/general.py b/app/task/general.py index 4a6b794..7bb3d61 100644 --- a/app/task/general.py +++ b/app/task/general.py @@ -983,7 +983,10 @@ class GeneralManager: ) # 发送自定义Webhook通知 - custom_webhooks = Config.get("Notify", "CustomWebhooks", []) + try: + custom_webhooks = Config.get("Notify", "CustomWebhooks") + except AttributeError: + custom_webhooks = [] if custom_webhooks: for webhook in custom_webhooks: if webhook.get("enabled", True): @@ -1027,7 +1030,10 @@ class GeneralManager: ) # 发送自定义Webhook通知 - custom_webhooks = Config.get("Notify", "CustomWebhooks", []) + try: + custom_webhooks = Config.get("Notify", "CustomWebhooks") + except AttributeError: + custom_webhooks = [] if custom_webhooks: for webhook in custom_webhooks: if webhook.get("enabled", True):