Skip to content

Commit

Permalink
feat: add notify test
Browse files Browse the repository at this point in the history
  • Loading branch information
moesnow committed Oct 6, 2023
1 parent cf6b523 commit e1e3c9f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 10 deletions.
10 changes: 9 additions & 1 deletion app/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def __init__(self, parent=None):
)

self.GameGroup = SettingCardGroup(self.tr("游戏设置"), self.scrollWidget)

self.gamePathCard = PushSettingCard(
self.tr('修改'),
FIF.GAME,
Expand Down Expand Up @@ -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原生通知'),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")))
Expand Down
92 changes: 85 additions & 7 deletions assets/config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' # 可选参数
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(_("按回车键关闭窗口. . ."))
Expand Down
2 changes: 1 addition & 1 deletion managers/notify_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion module/notify/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e1e3c9f

Please sign in to comment.