11
This commit is contained in:
+6
-1
@@ -26,6 +26,11 @@
|
|||||||
"default": ["QQ:GroupMessage:768280021","QQ:GroupMessage:690665795"]
|
"default": ["QQ:GroupMessage:768280021","QQ:GroupMessage:690665795"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"jx3api_token": {
|
||||||
|
"description": "JX3API Token",
|
||||||
|
"type": "string",
|
||||||
|
"default": "v2aa6e74d48abb7b9",
|
||||||
|
"hint": "前往https://www.jx3api.com/注册并获取Token。"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+33
-1
@@ -2,16 +2,18 @@ from datetime import datetime
|
|||||||
from typing import Dict, Any, Optional, List, Union
|
from typing import Dict, Any, Optional, List, Union
|
||||||
|
|
||||||
from astrbot.api import logger
|
from astrbot.api import logger
|
||||||
|
from astrbot.api import AstrBotConfig
|
||||||
|
|
||||||
from .request import APIClient
|
from .request import APIClient
|
||||||
from .aiosqlite import AsyncSQLite
|
from .aiosqlite import AsyncSQLite
|
||||||
from .function_basic import load_template,flatten_field,extract_fields,gold_to_string
|
from .function_basic import load_template,flatten_field,extract_fields,gold_to_string
|
||||||
|
|
||||||
class JX3Service:
|
class JX3Service:
|
||||||
def __init__(self, api_config,db: AsyncSQLite ):
|
def __init__(self, api_config,db: AsyncSQLite,config:AstrBotConfig):
|
||||||
self._api = APIClient()
|
self._api = APIClient()
|
||||||
self._db = db
|
self._db = db
|
||||||
self._api_config = api_config
|
self._api_config = api_config
|
||||||
|
self._config = config
|
||||||
|
|
||||||
|
|
||||||
def _init_return_data(self) -> Dict[str, Any]:
|
def _init_return_data(self) -> Dict[str, Any]:
|
||||||
@@ -591,3 +593,33 @@ class JX3Service:
|
|||||||
return_data["msg"] = "系统错误:数据处理失败"
|
return_data["msg"] = "系统错误:数据处理失败"
|
||||||
|
|
||||||
return return_data
|
return return_data
|
||||||
|
|
||||||
|
|
||||||
|
async def jueshemingpian(self, server: str, name:str ) -> Dict[str, Any]:
|
||||||
|
"""区服沙盘"""
|
||||||
|
return_data = self._init_return_data()
|
||||||
|
|
||||||
|
token = self._config.get("jx3api_token", "")
|
||||||
|
logger.info(f"使用的API Token: {token}")
|
||||||
|
|
||||||
|
if token == "":
|
||||||
|
return_data["msg"] = "系统未配置API访问Token"
|
||||||
|
return return_data
|
||||||
|
# 1. 构造请求参数
|
||||||
|
|
||||||
|
params = {"server": server, "name": name,"token": token}
|
||||||
|
|
||||||
|
# 2. 调用基础请求
|
||||||
|
data: Optional[Dict[str, Any]] = await self._base_request(
|
||||||
|
"jx3_jieshemingpian", "GET", params=params
|
||||||
|
)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return_data["msg"] = "获取接口信息失败"
|
||||||
|
return return_data
|
||||||
|
|
||||||
|
# 3. 处理返回数据 (直接提取图片 URL)
|
||||||
|
return_data["data"] = data
|
||||||
|
return_data["code"] = 200
|
||||||
|
|
||||||
|
return return_data
|
||||||
|
|||||||
@@ -145,5 +145,15 @@
|
|||||||
"key": "vBpEzoiC9z5A9c9Nn83IhLn6M9",
|
"key": "vBpEzoiC9z5A9c9Nn83IhLn6M9",
|
||||||
"id": "489048724"
|
"id": "489048724"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"jx3_jieshemingpian":{
|
||||||
|
"url":"https://www.jx3api.com/data/show/card",
|
||||||
|
"method":"GET",
|
||||||
|
"description":"此接口用于查询指定角色的名片墙信息,包括角色展示图片和展示数据的唯一标识。",
|
||||||
|
"params":{
|
||||||
|
"server": "眉间雪",
|
||||||
|
"name": "夜温言@长安城",
|
||||||
|
"token":""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ class Jx3ApiPlugin(Star):
|
|||||||
"""可选择实现异步的插件初始化方法,当实例化该插件类之后会自动调用该方法。"""
|
"""可选择实现异步的插件初始化方法,当实例化该插件类之后会自动调用该方法。"""
|
||||||
#创建类实例
|
#创建类实例
|
||||||
self.db = AsyncSQLite(str(self.file_local_data))
|
self.db = AsyncSQLite(str(self.file_local_data))
|
||||||
self.jx3fun = JX3Service(self.api_config,self.db)
|
self.jx3fun = JX3Service(self.api_config,self.db,self.conf)
|
||||||
self.at = AsyncTask(self.context, self.conf, self.jx3fun)
|
self.at = AsyncTask(self.context, self.conf, self.jx3fun)
|
||||||
# 周期函数调用
|
# 周期函数调用
|
||||||
self.kf_task = asyncio.create_task(self.at.cycle_kfjk())
|
self.kf_task = asyncio.create_task(self.at.cycle_kfjk())
|
||||||
@@ -267,6 +267,21 @@ class Jx3ApiPlugin(Star):
|
|||||||
yield event.plain_result("猪脑过载,请稍后再试")
|
yield event.plain_result("猪脑过载,请稍后再试")
|
||||||
|
|
||||||
|
|
||||||
|
@jx3.command("名片")
|
||||||
|
async def jx3_jueshemingpian(self, event: AstrMessageEvent,server: str = "梦江南", name: str = "飞翔大野猪"):
|
||||||
|
"""剑三 沙盘 服务器"""
|
||||||
|
try:
|
||||||
|
data= await self.jx3fun.jueshemingpian(server,name)
|
||||||
|
if data["code"] == 200:
|
||||||
|
yield event.image_result(data["data"]["showAvatar"])
|
||||||
|
else:
|
||||||
|
yield event.plain_result(data["msg"])
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"功能函数执行错误: {e}")
|
||||||
|
yield event.plain_result("猪脑过载,请稍后再试")
|
||||||
|
|
||||||
|
|
||||||
async def terminate(self):
|
async def terminate(self):
|
||||||
"""可选择实现异步的插件销毁方法,当插件被卸载/停用时会调用。"""
|
"""可选择实现异步的插件销毁方法,当插件被卸载/停用时会调用。"""
|
||||||
# 关闭数据库连接
|
# 关闭数据库连接
|
||||||
|
|||||||
Reference in New Issue
Block a user