From 13efe7fc4cad23745a9ec823ebb0df9b42959589 Mon Sep 17 00:00:00 2001 From: qsc20001102 Date: Tue, 20 Jan 2026 14:46:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E9=A9=AC=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _conf_schema.json | 56 +++++++++++++++++++++++++++++++++++++++++++ core/async_task.py | 9 +++++-- core/jx3_service.py | 36 ++++++++++++++++++++++++++-- data/api_config.json | 12 ++++++++++ data/local_async.json | 5 ++-- main.py | 14 +++++++++++ templates/helps.html | 12 +++++++++- 7 files changed, 137 insertions(+), 7 deletions(-) diff --git a/_conf_schema.json b/_conf_schema.json index 43ba513..0e238c9 100644 --- a/_conf_schema.json +++ b/_conf_schema.json @@ -72,5 +72,61 @@ "default": [] } } + }, + "smxx": { + "description": "刷马消息推送", + "type": "object", + "items": { + "enable": { + "description": "刷马消息推送功能开关", + "type": "bool", + "default": false, + "hint": "是否启用剑网三开刷马消息推送功能。" + }, + "time": { + "description": "获取最新消息循环时间", + "type": "int", + "default": 60, + "hint": "请求最新消息的循环时间,单位秒。" + }, + "umos": { + "description": "推送列表", + "type": "list", + "hint": "可以填写多个会话唯一ID。", + "items": { + "type": "string", + "description": "会话唯一ID,可通过/std获取" + }, + "default": [] + } + } + }, + "ctxx": { + "description": "赤兔消息推送", + "type": "object", + "items": { + "enable": { + "description": "赤兔消息推送功能开关", + "type": "bool", + "default": false, + "hint": "是否启用剑网三开赤兔消息推送功能。" + }, + "time": { + "description": "获取最新消息循环时间", + "type": "int", + "default": 60, + "hint": "请求最新消息的循环时间,单位秒。" + }, + "umos": { + "description": "推送列表", + "type": "list", + "hint": "可以填写多个会话唯一ID。", + "items": { + "type": "string", + "description": "会话唯一ID,可通过/std获取" + }, + "default": [] + } + } } } \ No newline at end of file diff --git a/core/async_task.py b/core/async_task.py index edaf1d7..a373556 100644 --- a/core/async_task.py +++ b/core/async_task.py @@ -1,3 +1,4 @@ +# pyright: reportArgumentType=false import asyncio import json import aiofiles @@ -22,7 +23,8 @@ class AsyncTask: self.context = context self.conf = config self.jx3fun = jx3fun - + + self.server = self.conf.get("server", "梦江南") self.file_path = StarTools.get_data_dir("astrbot_plugin_jx3") / "local_async.json" self._file_lock = asyncio.Lock() @@ -31,6 +33,7 @@ class AsyncTask: logger.info(f"获取后台数据缓存文件路径成功:{self.file_path}") + """===================== 本地读写 =====================""" async def set_local_data(self, key: str, value): @@ -109,8 +112,10 @@ class AsyncTask: async def init_tasks(self): settings = [ - ("kfjk", "开服监控", lambda: self.jx3fun.kaifu("梦江南")), + ("kfjk", "开服监控", lambda: self.jx3fun.kaifu(self.server)), ("xwzx", "新闻资讯", lambda: self.jx3fun.xinwen()), + ("smxx", "刷马消息", lambda: self.jx3fun.shuamamsg(self.server,type="horse",subtype="foreshow")), + ("ctxx", "赤兔消息", lambda: self.jx3fun.shuamamsg(self.server,type="chitu-horse",subtype="share_msg")), ] for key, name, fetch in settings: diff --git a/core/jx3_service.py b/core/jx3_service.py index 7d037ae..e26dc87 100644 --- a/core/jx3_service.py +++ b/core/jx3_service.py @@ -411,9 +411,10 @@ class JX3Service: async def xinwen(self) -> Dict[str, Any]: """新闻资讯""" return_data = self._init_return_data() - + # 提取字段可能返回列表 - data: Optional[List[Dict[str, Any]]] = await self._base_request("jx3_xinweng", "GET") + data: Optional[List[Dict[str, Any]]] = await self._base_request( + "jx3_xinweng", "GET") if not data or not isinstance(data, list): return_data["msg"] = "获取接口信息失败或数据格式错误" @@ -440,6 +441,37 @@ class JX3Service: return return_data + async def shuamamsg(self,server:str,type:str,subtype:str) -> Dict[str, Any]: + """刷马消息""" + return_data = self._init_return_data() + + params = {"server": server, "type": type, "subtype": subtype} + # 提取字段可能返回列表 + data: Optional[List[Dict[str, Any]]] = await self._base_request( + "jx3box_shuamamsg", "GET", params=params) + + if not data: + return_data["msg"] = "获取接口信息失败或数据格式错误" + return return_data + + try: + # + new_msg = data.get("list")[0] + return_data["status"] = new_msg.get('id') + + result_msg = f"{server}\n" + result_msg += f"{new_msg.get('content')}\n" + result_msg += f"{new_msg.get('created_at')}\n" + + return_data["data"] = result_msg + return_data["code"] = 200 + except Exception as e: + logger.error(f"jigai 数据处理时出错: {e}") + return_data["msg"] = "处理接口返回信息时出错" + + return return_data + + async def jinjia(self, server: str, limit:str) -> Dict[str, Any]: """区服金价""" return_data = self._init_return_data() diff --git a/data/api_config.json b/data/api_config.json index ad126be..ccdf478 100644 --- a/data/api_config.json +++ b/data/api_config.json @@ -250,5 +250,17 @@ "client": "std", "page": "1" } + }, + "jx3box_shuamamsg":{ + "url":"https://next2.jx3box.com/api/game/reporter/horse", + "method":"GET", + "description":"魔盒获取最新的刷马消息", + "params":{ + "pageIndex": "1", + "pageSize": "3", + "server": "梦江南", + "type": "horse", + "subtype": "foreshow" + } } } \ No newline at end of file diff --git a/data/local_async.json b/data/local_async.json index af3e31e..04568f3 100644 --- a/data/local_async.json +++ b/data/local_async.json @@ -1,5 +1,6 @@ { "kfjk": true, - "xwzx": 0, - "whgg": 0 + "xwzx": 3174, + "smxx": 0, + "ctxx": 0 } \ No newline at end of file diff --git a/main.py b/main.py index 622b138..c60a022 100644 --- a/main.py +++ b/main.py @@ -555,6 +555,20 @@ class Jx3ApiPlugin(Star): yield event.plain_result(return_msg) + @jx3.command("刷马推送") + async def jx3_shuamamsg(self, event: AstrMessageEvent): + """剑三 刷马推送""" + return_msg = await self.at.get_task_info("smxx") + yield event.plain_result(return_msg) + + + @jx3.command("赤兔推送") + async def jx3_chitusg(self, event: AstrMessageEvent): + """剑三 赤兔推送""" + return_msg = await self.at.get_task_info("ctxx") + yield event.plain_result(return_msg) + + async def terminate(self): """可选择实现异步的插件销毁方法,当插件被卸载/停用时会调用。""" if self.at: diff --git a/templates/helps.html b/templates/helps.html index 4c6844f..39b5a34 100644 --- a/templates/helps.html +++ b/templates/helps.html @@ -311,9 +311,19 @@
新闻推送
-
查看新闻推送状态的后台运行状况
+
推送最新的官方新闻资讯
剑三 新闻推送
+
+
刷马推送
+
推送最新的刷马消息
+
剑三 刷马推送
+
+
+
赤兔推送
+
推送最新的赤兔消息
+
剑三 赤兔推送
+