From 460afee768f3206ef0b77a401463529b502603a6 Mon Sep 17 00:00:00 2001 From: wumode Date: Mon, 4 Aug 2025 21:18:04 +0800 Subject: [PATCH] =?UTF-8?q?update(ClashRuleProvider):=20=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=8A=A8=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 3 ++- plugins.v2/clashruleprovider/README.md | 7 +++++- plugins.v2/clashruleprovider/__init__.py | 32 +++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/package.v2.json b/package.v2.json index 0bf3f8c..2ae3d43 100644 --- a/package.v2.json +++ b/package.v2.json @@ -462,11 +462,12 @@ "name": "Clash Rule Provider", "description": "随时为Clash添加一些额外的规则。", "labels": "工具", - "version": "1.3.1", + "version": "1.3.2", "icon": "Mihomo_Meta_A.png", "author": "wumode", "level": 1, "history": { + "v1.3.2": "注册插件动作", "v1.3.1": "支持配置 Hosts", "v1.2.8": "改进导入界面", "v1.2.7": "修复分享链接解析错误", diff --git a/plugins.v2/clashruleprovider/README.md b/plugins.v2/clashruleprovider/README.md index 0161977..b7ba572 100644 --- a/plugins.v2/clashruleprovider/README.md +++ b/plugins.v2/clashruleprovider/README.md @@ -5,6 +5,7 @@ - 即时通知 Clash 刷新规则集合 - 基于 Meta 内核丰富的代理组配置,提供灵活的路由功能 - 支持按大洲分组节点 +- GEO 规则输入提示 - 支持 [ACL4SSR](https://github.com/ACL4SSR/ACL4SSR) 规则集合 ## 配置说明 @@ -35,4 +36,8 @@ 在**高级选项**中启用按大洲分组节点。选择Asia以外的代理组,设置`url`: `https://chatgpt.com/` , `expected-status`: `200` 。 -![](https://images2.imgbox.com/e2/37/EoITSfRi_o.jpg) \ No newline at end of file +![](https://images2.imgbox.com/e2/37/EoITSfRi_o.jpg) + +### Hosts + +如果需要自动更新此处使用的 Cloudflare IP, 可以通过其它[插件](https://github.com/wumode/MoviePilot-Addons)实现。 \ No newline at end of file diff --git a/plugins.v2/clashruleprovider/__init__.py b/plugins.v2/clashruleprovider/__init__.py index f1df2c7..48765c6 100644 --- a/plugins.v2/clashruleprovider/__init__.py +++ b/plugins.v2/clashruleprovider/__init__.py @@ -20,6 +20,8 @@ from sse_starlette.sse import EventSourceResponse from app import schemas from app.core.config import settings +from app.core.event import eventmanager, Event +from app.schemas.types import EventType from app.log import logger from app.schemas.types import NotificationType from app.utils.ip import IpUtils @@ -38,7 +40,7 @@ class ClashRuleProvider(_PluginBase): # 插件图标 plugin_icon = "Mihomo_Meta_A.png" # 插件版本 - plugin_version = "1.3.1" + plugin_version = "1.3.2" # 插件作者 plugin_author = "wumode" # 作者主页 @@ -103,6 +105,7 @@ class ClashRuleProvider(_PluginBase): _geo_rules: Dict[str, List[str]] = {'geoip': [], 'geosite': []} def init_plugin(self, config: dict = None): + self.stop_service() self._ruleset_rules = self.get_data("ruleset_rules") self._top_rules = self.get_data("top_rules") self._proxy_groups = self.get_data("proxy_groups") or [] @@ -486,7 +489,14 @@ class ClashRuleProvider(_PluginBase): """ 退出插件 """ - pass + if self._scheduler: + try: + self._scheduler.remove_all_jobs() + if self._scheduler.running: + self._scheduler.shutdown() + self._scheduler = None + except Exception as e: + logger.error(f"退出插件失败:{e}") def get_service(self) -> List[Dict[str, Any]]: if self.get_state() and self._auto_update_subscriptions and self._sub_links: @@ -576,10 +586,10 @@ class ClashRuleProvider(_PluginBase): async def fetch_clash_data(self, endpoint: str) -> Dict: clash_headers = {"Authorization": f"Bearer {self._clash_dashboard_secret}"} url = f"{self._clash_dashboard_url}/{endpoint}" - response = await AsyncRequestUtils().get_res(url, headers=clash_headers, timeout=10) + response = await AsyncRequestUtils().get_json(url, headers=clash_headers, timeout=10) if response is None: raise HTTPException(status_code=502, detail=f"Failed to fetch {endpoint}") - return response.json() + return response async def clash_proxy(self, path: str) -> Dict: return await self.fetch_clash_data(path) @@ -1329,6 +1339,8 @@ class ClashRuleProvider(_PluginBase): return None def __add_notification_job(self, ruleset_names: List[str]): + if not self._enabled or not self._scheduler: + return for ruleset in ruleset_names: if ruleset in self._rule_provider: self._scheduler.add_job(self.notify_clash, "date", @@ -1509,3 +1521,15 @@ class ClashRuleProvider(_PluginBase): def best_cf_ipv6(self) -> List[str]: v6 = [ip for ip in self._best_cf_ip if IpUtils.is_ipv6(ip)] return v6 + + @eventmanager.register(EventType.PluginAction) + def update_cloudflare_ips_handler(self, event:Event = None): + event_data = event.event_data + if not event_data or event_data.get("action") != "update_cloudflare_ips": + return + ips = event_data.get("ips") + if isinstance(ips, str): + ips = [ips] + if isinstance(ips, list): + logger.info(f"更新 Clooudflare 优选 IP ...") + self.update_best_cf_ip(ips) \ No newline at end of file