添加 Discord Webhook 通知功能 - #1282
Conversation
aa7629e to
b2a57cf
Compare
There was a problem hiding this comment.
🎯 Core Changes
- Implemented Discord Webhook notification system for task alerts.
- Refactored
BaseWWTaskto automatically handle notifications whennotify=Trueis passed tolog_infoorlog_error. - Integrated notification content with the project's i18n system for multilingual support.
- Added UI configuration for Webhook URL, username, and optional screenshot attachments.
- Discord API Compatibility: The implementation uses non-standard component types (9, 10, 11, 17) and internal flags (
1 << 15) that are not part of the official Discord Webhook API. This will likely result in400 Bad Requesterrors for standard webhooks. Using standardembedsis the reliable approach. - Performance: Notification delivery is synchronous. Uploading screenshots over a slow connection will block the automation task thread, potentially causing frame drops or logic timing issues in the game.
Code review performed by GOOGLE - gemini-3-flash-preview.
| if not has_screenshot: | ||
| return {"content": content} | ||
|
|
||
| return { |
There was a problem hiding this comment.
The component types used here (17, 9, 10, 11) and the flag 1 << 15 are internal or experimental Discord structures not supported by standard Webhooks. This payload structure is likely to be rejected by Discord with a 400 error. It is highly recommended to use the standard 'embeds' field for rich content and to display screenshots via attachment://screenshot.jpg.
| } | ||
|
|
||
| @staticmethod | ||
| def _enable_components(url: str) -> str: |
There was a problem hiding this comment.
The query parameter with_components=true is used for fetching messages with components via GET requests in the REST API. It is not a standard or required parameter for POSTing to a Discord Webhook and should be removed.
| import requests | ||
|
|
||
| if image_bytes is None: | ||
| response = requests.post(self.webhook_url, json=payload, timeout=self.timeout) |
There was a problem hiding this comment.
This POST request is synchronous and blocking. Uploading game screenshots can take significant time depending on network conditions. This will pause the entire automation task loop. Consider executing the notification delivery in a background thread.
There was a problem hiding this comment.
已处理:DiscordWebhookNotifier.send() 仍然是单次 HTTP 发送函数,但调用方 NotificationService 已经改为后台 daemon thread 发送,并在入队前复制截图帧,因此自动化任务循环不会等待网络上传完成。
| from src.notification.notification_service import NotificationService | ||
|
|
||
| logger = Logger.get_logger(__name__) | ||
| notification_config = dict(notification_config_option.default_config) |
There was a problem hiding this comment.
The test function loads configuration from the file system. If a user modifies the Webhook URL in the UI and clicks 'Send Test Notification' before clicking 'Save', the test will use the old/empty configuration from the disk, leading to confusing failures.
There was a problem hiding this comment.
已修复:测试通知不再从磁盘读取 Notification Config.json,改为通过 og.global_config.get_config(notification_config_option) 使用应用当前持有的配置,避免 UI 当前配置与磁盘文件不一致。
b2a57cf to
a6a528b
Compare
|
已按 AI Review 的两点建议调整:
验证:
备注:最新一次 AI Code Review workflow 失败是 Gemini API |
a6a528b to
56f47a4
Compare
There was a problem hiding this comment.
🎯 Core Changes
- Discord Webhook Integration: Adds functionality to send notifications to Discord via webhooks, including support for custom usernames and user mentions.
- Configurable Notifications: Users can now toggle notifications for
INFOandERRORlevels separately and choose whether to attach a game screenshot. - Localization Support: Task notifications are integrated into the existing
i18nframework, allowing localized alerts for various languages. - Test Utility: Adds a "Send Test Notification" button in the configuration GUI for quick verification.
- Privacy Masking: Implements
make_bottom_right_blackas a screenshot processor to obscure sensitive on-screen information (like game UIDs) before sending to Discord.
- None. The implementation uses daemon threads for network requests to avoid blocking the main automation loop, and the configuration is opt-in, ensuring no impact on existing users.
Code review performed by GOOGLE - gemini-3-flash-preview.
|
日常一条龙这种定时自启动的任务很需要做外部通知,其它的任务我觉得加了意义不大 |
There was a problem hiding this comment.
🎯 Core Changes
- Discord Notification System: Fully implemented the Discord Webhook notification service with task-level granularity.
- Asynchronous Execution: Notification delivery (including screenshot uploads) is now handled in a background daemon thread, preventing the main automation loop from blocking on network IO.
- Configuration & Validation: Added a "Send Test Notification" button in the UI and implemented validation logic to warn users if notifications are enabled without a Webhook URL.
- Internationalization: All notification messages are now routed through the project's
i18nsystem, with Japanese translations updated. - Privacy: Screenshots sent via notifications are processed by
make_bottom_right_black(likely to hide UIDs).
Fixed issues from previous reviews regarding blocking requests and incorrect configuration source for test notifications.
Verdict: Approve - The implementation is clean, follows established patterns, and addresses all previous performance and logic concerns.
Code review performed by GOOGLE - gemini-3-flash-preview.
|
已根据反馈调整通知开关粒度:
验证:
|
ab0c4c9 to
ffc3da6
Compare
There was a problem hiding this comment.
🎯 Core Changes
- Added internationalization (i18n) support for the Discord Webhook notification feature.
- Provided localized strings for Spanish (es_ES), Korean (ko_KR), Simplified Chinese (zh_CN), and Traditional Chinese (zh_TW).
Verdict: Approve. The translations correctly map the new configuration options and log messages, completing the feature integration across supported locales.
Code review performed by GOOGLE - gemini-3-flash-preview.
我只是提个个人建议,虽然我是觉得通知功能很有帮助,但是具体你还是需要和 @ok-oldking 交流。比如,可能要考虑把通知集成在ok-script里,而不是在这个项目里给log打补丁。 |
|
改动太多了, 要加也是要加在ok-script库里 |
There was a problem hiding this comment.
🎯 核心变更
- 功能迁移与重构:将原有的 Discord Webhook 通知逻辑从本地代码迁移到了
ok框架内置的通知系统中。为此删除了src/notification目录下的服务代码,并从config.py中移除了本地定义的配置项。 - 重构日志与通知接口:重构了
BaseWWTask中的log_info和log_error方法。现在它们会先格式化消息,调用父类日志方法(同时显式禁用父类通知),然后根据任务配置通过框架的self.notification发送外部通知。这一改变使通知逻辑更加统一且易于维护。 - 多语言支持补全:同步更新了西班牙语、日语、韩语及中文(简/繁)的语言包,增加了通知配置及外部推送相关的词条翻译。
- 依赖版本:由于本地
Notification Config已移除,该功能的可用性完全依赖于底层ok框架。请确保框架版本已同步发布并包含对应的内置配置逻辑,否则 UI 中的通知设置可能会消失。
Code review performed by GOOGLE - gemini-3-flash-preview.
b51e99d to
34fe567
Compare
34fe567 to
3bee6b9
Compare
|
|
有没有考虑设置成通用的post url和post body, 实现多平台通知? (参考明日方舟MAA的方案) |



变更内容
依赖
测试
备注