From c12cd5779b066b92a780e3bb7ed99dfa501f4dcc Mon Sep 17 00:00:00 2001 From: thsrite Date: Sun, 7 Apr 2024 16:07:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=89=B9=E5=AE=9A=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E6=8C=87=E5=AE=9Auserid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/WeChatForward.md | 18 +++++++- package.json | 2 +- plugins/wechatforward/__init__.py | 77 ++++++++++++++++++------------- 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/docs/WeChatForward.md b/docs/WeChatForward.md index ee7b246..b9c79ca 100644 --- a/docs/WeChatForward.md +++ b/docs/WeChatForward.md @@ -2,13 +2,14 @@ ### 更新记录 +- 1.4 特定消息强制指定userid - 1.3 防重复发送额外消息 - 1.2 fix规则 - 1.1 自定义发送额外消息 - 1.0 根据正则转发通知到其他WeChat应用 -消息转发插件加强版 +#### 消息转发插件加强版 根据正则表达式将对应title的消息转发到不同的企业微信应用上 @@ -16,12 +17,25 @@ 如果某条消息不想指定userid发送,则填写忽略userid正则表达式. -额外消息配置 +#### 额外消息配置 + `开始下载 > userid > 后台下载任务已提交,请耐心等候入库通知。 > appid` + `已添加订阅 > userid > 电视剧正在更新,已添加订阅,待更新后自动下载。 > appid` + 中间用` > `分割 消息title匹配到`开始下载`的正则 + 且消息text中的`用户:`匹配到userid, + 则发送`后台下载任务已提交,请耐心等候入库通知。`额外通知。 + 发送给appid为`appid`的企业微信应用。(环境变量配置或者本插件配置均可。) + + +#### 特定消息指定用户 + +`title正则 > text正则 > userid` + +当要发送的消息的title和text均匹配正则,则强制指定该消息的userid \ No newline at end of file diff --git a/package.json b/package.json index 0d638c7..5583579 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,7 @@ "WeChatForward": { "name": "微信消息转发", "description": "根据正则转发通知到其他WeChat应用。", - "version": "1.3", + "version": "1.4", "icon": "Wechat_A.png", "author": "thsrite", "level": 1 diff --git a/plugins/wechatforward/__init__.py b/plugins/wechatforward/__init__.py index 381ee84..8c58a4d 100644 --- a/plugins/wechatforward/__init__.py +++ b/plugins/wechatforward/__init__.py @@ -22,7 +22,7 @@ class WeChatForward(_PluginBase): # 插件图标 plugin_icon = "Wechat_A.png" # 插件版本 - plugin_version = "1.3" + plugin_version = "1.4" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -42,6 +42,7 @@ class WeChatForward(_PluginBase): _extra_confs = None _pattern_token = {} _extra_msg_history = {} + _specify_confs = {} # 企业微信发送消息URL _send_msg_url = f"{settings.WECHAT_PROXY}/cgi-bin/message/send?access_token=%s" @@ -55,6 +56,7 @@ class WeChatForward(_PluginBase): self._pattern = config.get("pattern") self._ignore_userid = config.get("ignore_userid") self._extra_confs = config.get("extra_confs") + self._specify_confs = config.get("specify_confs") # 获取token存库 if self._enabled and self._wechat: @@ -155,10 +157,10 @@ class WeChatForward(_PluginBase): { 'component': 'VTextarea', 'props': { - 'model': 'ignore_userid', - 'rows': '1', - 'label': '忽略userid', - 'placeholder': '开始下载|添加下载任务失败' + 'model': 'extra_confs', + 'rows': '4', + 'label': '额外消息配置', + 'placeholder': '开始下载 > userid > 后台下载任务已提交,请耐心等候入库通知。 > appid' } } ] @@ -177,10 +179,32 @@ class WeChatForward(_PluginBase): { 'component': 'VTextarea', 'props': { - 'model': 'extra_confs', - 'rows': '5', - 'label': '额外消息配置', - 'placeholder': '开始下载 > userid > 后台下载任务已提交,请耐心等候入库通知。 > appid' + 'model': 'specify_confs', + 'rows': '2', + 'label': '特定消息指定用户', + 'placeholder': 'title > text > userid' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VTextarea', + 'props': { + 'model': 'ignore_userid', + 'rows': '1', + 'label': '忽略userid', + 'placeholder': '开始下载|添加下载任务失败' } } ] @@ -202,34 +226,14 @@ class WeChatForward(_PluginBase): 'type': 'info', 'variant': 'tonal', 'text': '根据正则表达式,把MoviePilot的消息转发到多个微信应用。' - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - }, - 'content': [ - { - 'component': 'VAlert', - 'props': { - 'type': 'info', - 'variant': 'tonal', - 'text': '应用配置可加注释:' + '应用配置可加注释:' 'appid:corpid:appsecret#站点通知' } } ] } ] - } + }, ] } ], { @@ -237,6 +241,7 @@ class WeChatForward(_PluginBase): "wechat": "", "pattern": "", "ignore_userid": "", + "specify_confs": "", "extra_confs": "" } @@ -276,6 +281,16 @@ class WeChatForward(_PluginBase): if self._ignore_userid and re.search(self._ignore_userid, title): userid = None + # 特定消息指定用户 + if self._specify_confs: + for specify_conf in self._specify_confs.split("\n"): + specify = specify_conf.split(" > ") + if len(specify) != 3: + continue + if re.search(specify[0], title) and re.search(specify[0], text): + userid = specify[2] + break + # 发送消息 if image: self.__send_image_message(title, text, image, userid, access_token, appid, index)