From e1e3c9f5e05418840cd940bc7bb48f55ed085476 Mon Sep 17 00:00:00 2001 From: moesnow <11678347+moesnow@users.noreply.github.com> Date: Sat, 7 Oct 2023 01:57:57 +0800 Subject: [PATCH] feat: add notify test --- app/setting_interface.py | 10 +++- assets/config/config.example.yaml | 92 ++++++++++++++++++++++++++++--- main.py | 8 +++ managers/notify_manager.py | 2 +- module/notify/notify.py | 3 +- 5 files changed, 105 insertions(+), 10 deletions(-) diff --git a/app/setting_interface.py b/app/setting_interface.py index 70ef6437..18028d4c 100644 --- a/app/setting_interface.py +++ b/app/setting_interface.py @@ -96,7 +96,6 @@ def __init__(self, parent=None): ) self.GameGroup = SettingCardGroup(self.tr("游戏设置"), self.scrollWidget) - self.gamePathCard = PushSettingCard( self.tr('修改'), FIF.GAME, @@ -369,6 +368,12 @@ def __init__(self, parent=None): ) self.NotifyGroup = SettingCardGroup(self.tr("消息推送"), self.scrollWidget) + self.testNotifyCard = PrimaryPushSettingCard( + self.tr('发送消息'), + FIF.TILES, + self.tr("测试消息推送"), + "" + ) self.winotifyEnableCard = SwitchSettingCard1( FIF.BACK_TO_WINDOW, self.tr('启用Windows原生通知'), @@ -487,6 +492,7 @@ def __initLayout(self): self.ForgottenhallGroup.addSettingCard(self.forgottenhallTeam2Card) self.ForgottenhallGroup.addSettingCard(self.forgottenhallRunTimeCard) + self.NotifyGroup.addSettingCard(self.testNotifyCard) self.NotifyGroup.addSettingCard(self.winotifyEnableCard) self.KeybindingGroup.addSettingCard(self.keybindingTechniqueCard) @@ -600,6 +606,8 @@ def __connectSignalToSlot(self): self.updateUniverseCard.clicked.connect(lambda: start_task("universe_update")) self.updateFightCard.clicked.connect(lambda: start_task("fight_update")) + self.testNotifyCard.clicked.connect(lambda: start_task("notify")) + self.githubCard.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("https://github.com/moesnow/March7thAssistant"))) self.qqGroupCard.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("https://qm.qq.com/q/9gFqUrUGVq"))) self.feedbackCard.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("https://github.com/moesnow/March7thAssistant/issues"))) diff --git a/assets/config/config.example.yaml b/assets/config/config.example.yaml index c97ef78b..b727a6a5 100644 --- a/assets/config/config.example.yaml +++ b/assets/config/config.example.yaml @@ -115,17 +115,95 @@ forgottenhall_timestamp: 0 # 上次运行混沌回忆的时间戳(每周运行 hotkey_technique: e # 游戏内设置的秘技按键 -# 可选消息通知 Telegram已适配支持发送截图 -# 还支持更多推送查看下面的链接仿照格式配置即可 -# https://github.com/LmeSzinc/AzurLaneAutoScript/wiki/Onepush-configuration-[CN] -notify_winotify_enable: true # 启用Windows原生通知 +# 消息通知 +# Windows 原生通知 +notify_winotify_enable: false -notify_telegram_enable: false # 启用Telegram通知 +# Telegram 通知 +# 已适配支持发送截图 +# 依赖科学上网环境 +notify_telegram_enable: false notify_telegram_token: '' notify_telegram_userid: '' -notify_telegram_api_url: '' +notify_telegram_api_url: '' # 可选参数 -notify_wechatworkapp_enable: false # 启用企业微信应用通知 +# Server 酱 Turbo 版通知 +# 扫码登陆 微信推送 适合小白 免费版每天限制五条 +# https://sct.ftqq.com/ +notify_serverchanturbo_enable: false +notify_serverchanturbo_sctkey: '' +notify_serverchanturbo_channel: '' # 可选参数 +notify_serverchanturbo_openid: '' # 可选参数 + +# Bark 通知 +# 推荐 iOS 用户使用 +# 直接在 App Store 下载安装 +notify_bark_enable: false +notify_bark_key: '' +notify_bark_sound: '' # 可选参数 +notify_bark_isarchive: '1' # 可选参数 +notify_bark_icon: 'https://cdn.jsdelivr.net/gh/moesnow/March7thAssistant@main/assets/app/images/March7th.jpg' # 可选参数 +notify_bark_group: 'March7thAssistant' # 可选参数 +notify_bark_url: '' # 可选参数 +notify_bark_copy: '' # 可选参数 +notify_bark_autocopy: '' # 可选参数 + +# 邮箱 smtp 通知 +# 注意部分邮箱密码部分需要填写授权码(比如QQ邮箱) +notify_smtp_enable: false +notify_smtp_host: '' +notify_smtp_user: '' +notify_smtp_password: '' +notify_smtp_From: '' # 可选参数 +notify_smtp_To: '' # 可选参数 +notify_smtp_port: '' # 可选参数 +notify_smtp_ssl: '' # 可选参数 + +# 钉钉通知 +notify_dingtalk_enable: false +notify_dingtalk_token: '' + +# pushplus 通知 +notify_pushplus_enable: false +notify_pushplus_token: '' +notify_pushplus_channel: '' # 可选参数 +notify_pushplus_webhook: '' # 可选参数 +notify_pushplus_callbackUrl: '' # 可选参数 + +# 企业微信应用通知 +notify_wechatworkapp_enable: false notify_wechatworkapp_corpid: '' notify_wechatworkapp_corpsecret: '' notify_wechatworkapp_agentid: '' +notify_wechatworkapp_touser: '' # 可选参数 + +# 企业微信机器人通知 +notify_wechatworkbot_enable: false +notify_wechatworkbot_key: '' + +# gocqhttp 通知 +notify_gocqhttp_enable: false +notify_gocqhttp_endpoint: '' +notify_gocqhttp_message_type: '' +notify_gocqhttp_token: '' # 可选参数 +notify_gocqhttp_user_id: '' # 可选参数 +notify_gocqhttp_group_id: '' # 可选参数 + +# discord 通知 +notify_discord_enable: false +notify_discord_webhook: '' +notify_discord_username: '' # 可选参数 +notify_discord_avatar_url: '' # 可选参数 +notify_discord_color: '' # 可选参数 + +# pushdeer 通知 +notify_pushdeer_enable: false +notify_pushdeer_token: '' +notify_pushdeer_url: '' # 可选参数 + +# 飞书通知 +notify_lark_enable: false +notify_lark_webhook: '' +notify_lark_content: '' +notify_lark_keyword: '' # 可选参数 +notify_lark_sign: '' # 可选参数 diff --git a/main.py b/main.py index 366b2d98..088134c5 100644 --- a/main.py +++ b/main.py @@ -58,6 +58,14 @@ def main(action=None): Fight.update() input(_("按回车键关闭窗口. . .")) sys.exit(0) + elif action == "notify": + from io import BytesIO + from PIL import Image + image_io = BytesIO() + Image.open("./assets/app/images/March7th.jpg").save(image_io, format='JPEG') + notify.notify(_("三月七小助手|・ω・)"), _("这是一条测试消息"),image_io) + input(_("按回车键关闭窗口. . .")) + sys.exit(0) else: logger.error(_("未知任务: {action}").format(action=action)) input(_("按回车键关闭窗口. . .")) diff --git a/managers/notify_manager.py b/managers/notify_manager.py index 52ca7cba..8fbf7def 100644 --- a/managers/notify_manager.py +++ b/managers/notify_manager.py @@ -8,7 +8,7 @@ notifier_name = key[len("notify_"):-len("_enable")] params = {} for param_key, param_value in config.config.items(): - if param_key.startswith("notify_" + notifier_name + "_") and param_key != f"notify_{notifier_name}_enable": + if param_key.startswith("notify_" + notifier_name + "_") and param_key != f"notify_{notifier_name}_enable" and param_value != "": params[param_key[len("notify_" + notifier_name + "_"):]] = param_value notify.set_notifier(notifier_name, True, params) diff --git a/module/notify/notify.py b/module/notify/notify.py index 8ecfd17f..687fcea6 100644 --- a/module/notify/notify.py +++ b/module/notify/notify.py @@ -65,7 +65,7 @@ def _send_notification_with_image(self, notifier_name, title, content, image_io) if notifier_params: token = notifier_params["token"] chat_id = notifier_params["userid"] - api_url = notifier_params["api_url"] if notifier_params["api_url"] else "api.telegram.org" + api_url = notifier_params["api_url"] if "api_url" in notifier_params else "api.telegram.org" tgurl = f"https://{api_url}/bot{token}/sendPhoto" message = content if title and content: @@ -101,6 +101,7 @@ def _send_notification_by_winotify(self, title, content): icon=os.getcwd() + "\\assets\\app\\images\\March7th.jpg") toast.set_audio(audio.Mail, loop=False) toast.show() + logger.info(_("{notifier_name} 通知发送完成").format(notifier_name="winotify")) def notify(self, title="", content="", image_io=None): for notifier_name in self.notifiers: