feat(notify): 实现自定义Webhook通知功能

This commit is contained in:
2025-09-27 16:22:04 +08:00
parent 13caed7207
commit d2066e9631
5 changed files with 386 additions and 81 deletions

View File

@@ -1906,12 +1906,19 @@ class MaaManager:
Config.get("Notify", "ServerChanKey"),
)
if Config.get("Notify", "IfCompanyWebHookBot"):
await Notify.WebHookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
Config.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送自定义Webhook通知
custom_webhooks = Config.get("Notify", "CustomWebhooks", [])
if custom_webhooks:
for webhook in custom_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
elif mode == "统计信息":
@@ -1962,12 +1969,19 @@ class MaaManager:
Config.get("Notify", "ServerChanKey"),
)
if Config.get("Notify", "IfCompanyWebHookBot"):
await Notify.WebHookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
Config.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送自定义Webhook通知
custom_webhooks = Config.get("Notify", "CustomWebhooks", [])
if custom_webhooks:
for webhook in custom_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
# 发送用户单独通知
if self.cur_user_data.get("Notify", "Enabled") and self.cur_user_data.get(
@@ -2000,13 +2014,19 @@ class MaaManager:
)
# 推送CompanyWebHookBot通知
if self.cur_user_data.get("Notify", "IfCompanyWebHookBot"):
if self.cur_user_data.get("Notify", "CompanyWebHookBotUrl"):
await Notify.WebHookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
self.cur_user_data.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送用户自定义Webhook通知
user_webhooks = self.cur_user_data.get("Notify", {}).get("CustomWebhooks", [])
if user_webhooks:
for webhook in user_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
else:
logger.error(
"用户CompanyWebHookBot密钥为空, 无法发送用户单独的CompanyWebHookBot通知"
@@ -2034,16 +2054,19 @@ class MaaManager:
Config.get("Notify", "ServerChanKey"),
)
if Config.get("Notify", "IfCompanyWebHookBot"):
await Notify.WebHookPush(
title,
"好羡慕~\n\nAUTO-MAS 敬上",
Config.get("Notify", "CompanyWebHookBotUrl"),
)
await Notify.CompanyWebHookBotPushImage(
Path.cwd() / "res/images/notification/six_star.png",
Config.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送自定义Webhook通知(六星喜报)
custom_webhooks = Config.get("Notify", "CustomWebhooks", [])
if custom_webhooks:
for webhook in custom_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
"好羡慕~\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
# 发送用户单独通知
if self.cur_user_data.get("Notify", "Enabled") and self.cur_user_data.get(
@@ -2077,17 +2100,19 @@ class MaaManager:
)
# 推送CompanyWebHookBot通知
if self.cur_user_data.get("Notify", "IfCompanyWebHookBot"):
if self.cur_user_data.get("Notify", "CompanyWebHookBotUrl"):
await Notify.WebHookPush(
title,
"好羡慕~\n\nAUTO-MAS 敬上",
self.cur_user_data.get("Notify", "CompanyWebHookBotUrl"),
)
await Notify.CompanyWebHookBotPushImage(
Path.cwd() / "res/images/notification/six_star.png",
self.cur_user_data.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送用户自定义Webhook通知(六星喜报)
user_webhooks = self.cur_user_data.get("Notify", {}).get("CustomWebhooks", [])
if user_webhooks:
for webhook in user_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
"好羡慕~\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
else:
logger.error(
"用户CompanyWebHookBot密钥为空, 无法发送用户单独的CompanyWebHookBot通知"

View File

@@ -982,12 +982,19 @@ class GeneralManager:
Config.get("Notify", "ServerChanKey"),
)
if Config.get("Notify", "IfCompanyWebHookBot"):
await Notify.WebHookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
Config.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送自定义Webhook通知
custom_webhooks = Config.get("Notify", "CustomWebhooks", [])
if custom_webhooks:
for webhook in custom_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
elif mode == "统计信息":
@@ -1019,12 +1026,19 @@ class GeneralManager:
Config.get("Notify", "ServerChanKey"),
)
if Config.get("Notify", "IfCompanyWebHookBot"):
await Notify.WebHookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
Config.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送自定义Webhook通知
custom_webhooks = Config.get("Notify", "CustomWebhooks", [])
if custom_webhooks:
for webhook in custom_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
# 发送用户单独通知
if self.cur_user_data.get("Notify", "Enabled") and self.cur_user_data.get(
@@ -1057,13 +1071,19 @@ class GeneralManager:
)
# 推送CompanyWebHookBot通知
if self.cur_user_data.get("Notify", "IfCompanyWebHookBot"):
if self.cur_user_data.get("Notify", "CompanyWebHookBotUrl"):
await Notify.WebHookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
self.cur_user_data.get("Notify", "CompanyWebHookBotUrl"),
)
# 发送用户自定义Webhook通知
user_webhooks = self.cur_user_data.get("Notify", {}).get("CustomWebhooks", [])
if user_webhooks:
for webhook in user_webhooks:
if webhook.get("enabled", True):
try:
await Notify.CustomWebhookPush(
title,
f"{message_text}\n\nAUTO-MAS 敬上",
webhook
)
except Exception as e:
logger.error(f"用户自定义Webhook推送失败 ({webhook.get('name', 'Unknown')}): {e}")
else:
logger.error(
"用户CompanyWebHookBot密钥为空, 无法发送用户单独的CompanyWebHookBot通知"