From 787e66bcbc0f3247cdf474849ca34f4a927f5000 Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 21 Oct 2024 16:35:37 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=BE=AE=E4=BF=A1=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=20v2.8=20=E5=85=BC=E5=AE=B9v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.v2.json | 3 +- plugins.v2/wechatforward/__init__.py | 97 ++++------------------------ 3 files changed, 15 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 844f14e..a57f4f9 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ 31. [短剧刮削 v3.2](docs%2FShortPlayMonitor.md) `监控视频短剧创建,刮削。` 32. 云盘实时监控 v2.4.6 `监控云盘目录文件变化,自动转移链接。` 33. 源文件恢复 v1.2 `根据MoviePilot的转移记录中的硬链文件恢复源文件。` -34. [微信消息转发 v2.7](docs%2FWeChatForward.md) `根据正则转发通知到其他WeChat应用。` +34. [微信消息转发 v2.8](docs%2FWeChatForward.md) `根据正则转发通知到其他WeChat应用。` 35. 订阅下载统计 v1.6 `统计指定时间内各站点订阅及下载情况。` 36. [自定义命令 v1.7](docs%2FCustomCommand.md) `自定义执行周期执行命令并推送结果。` 37. docker自定义任务 v1.3 `管理宿主机docker,自定义容器定时任务。` diff --git a/package.v2.json b/package.v2.json index 3fbeddc..f83561b 100644 --- a/package.v2.json +++ b/package.v2.json @@ -93,11 +93,12 @@ "name": "微信消息转发", "description": "根据正则转发通知到其他WeChat应用。", "labels": "消息通知", - "version": "2.7", + "version": "2.8", "icon": "Wechat_A.png", "author": "thsrite", "level": 1, "history": { + "v2.8": "兼容v2", "v2.7": "特殊消息指定用户支持title匹配", "v2.6": "已完成订阅额外消息查询订阅历史订阅用户", "v2.5.1": "修复token过期重发未存储userid问题", diff --git a/plugins.v2/wechatforward/__init__.py b/plugins.v2/wechatforward/__init__.py index 25c72d4..819fb21 100644 --- a/plugins.v2/wechatforward/__init__.py +++ b/plugins.v2/wechatforward/__init__.py @@ -21,7 +21,7 @@ class WeChatForward(_PluginBase): # 插件图标 plugin_icon = "Wechat_A.png" # 插件版本 - plugin_version = "2.7" + plugin_version = "2.8" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -45,9 +45,9 @@ class WeChatForward(_PluginBase): _wechat_proxy = None # 企业微信发送消息URL - _send_msg_url = None + _send_msg_url = "%s/cgi-bin/message/send?access_token=%s" # 企业微信获取TokenURL - _token_url = None + _token_url = "%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s" example = [ { @@ -80,85 +80,10 @@ class WeChatForward(_PluginBase): self._wechat_proxy = config.get("wechat_proxy") self._history_days = config.get("history_days") or 7 - # 企业微信发送消息URL - _send_msg_url = "%s/cgi-bin/message/send?access_token=%s" - # 企业微信获取TokenURL - _token_url = "%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s" - - # 兼容旧版本配置 - self.__sync_old_config() - # 获取token存库 if self._enabled and self._wechat_confs: self.__save_wechat_token() - def __sync_old_config(self): - """ - 兼容旧版本配置 - """ - config = self.get_config() - if not config or not config.get("wechat") or not config.get("pattern"): - return - - __extra_confs = {} - if config.get("extra_confs"): - for extra_conf in config.get("extra_confs").split("\n"): - if not extra_conf: - continue - if str(extra_conf).startswith("#"): - extra_conf = extra_conf.strip()[1:] - extras = str(extra_conf).split(" > ") - if len(extras) != 4: - continue - extra_pattern = extras[0] - extra_userid = extras[1] - extra_title = extras[2] - extra_appid = extras[3] - __extra = __extra_confs.get(extra_appid, []) - __extra.append({ - "pattern": extra_pattern, - "userid": extra_userid, - "msg": extra_title, - }) - __extra_confs[extra_appid] = __extra - - wechat_confs = [] - for index, wechat in enumerate(config.get("wechat").split("\n")): - remark = "" - if wechat.count("#") == 1: - remark = wechat.split("#")[1] - wechat = wechat.split("#")[0] - wechat_config = wechat.split(":") - if len(wechat_config) != 3: - continue - appid = wechat_config[0] - corpid = wechat_config[1] - appsecret = wechat_config[2] - if not remark: - remark = f"{appid}配置" - - # 获取对应appid的正则 - pattern = config.get("pattern").split("\n")[index] or "" - wechat_confs.append({ - "remark": remark, - "appid": appid, - "corpid": corpid, - "appsecret": appsecret, - "pattern": pattern, - "extra_confs": __extra_confs.get(appid, []) if __extra_confs else [] - }) - - if wechat_confs: - self._wechat_confs = json.dumps(wechat_confs, indent=4, ensure_ascii=False) - self.update_config({ - "enabled": self._enabled, - "wechat_confs": self._wechat_confs, - "ignore_userid": self._ignore_userid, - "specify_confs": self._specify_confs, - "wechat_proxy": self._wechat_proxy, - }) - logger.info("旧版本配置已转为新版本配置") - def __save_wechat_token(self): """ 获取并存储wechat token @@ -167,13 +92,15 @@ class WeChatForward(_PluginBase): if self._rebuild: self.__parse_token() else: - # 从数据库获取token - wechat_confs = self.get_data('wechat_confs') - - if not self._wechat_token_pattern_confs and wechat_confs: - self._wechat_token_pattern_confs = wechat_confs - logger.info(f"WeChat配置 从数据库获取成功:{len(self._wechat_token_pattern_confs.keys())}条配置") - else: + try: + # 从数据库获取token + wechat_confs = self.get_data('wechat_confs') + if not self._wechat_token_pattern_confs and wechat_confs: + self._wechat_token_pattern_confs = wechat_confs + logger.info(f"WeChat配置 从数据库获取成功:{len(self._wechat_token_pattern_confs.keys())}条配置") + else: + self.__parse_token() + except Exception as e: self.__parse_token() def __parse_token(self):