196 lines
6.1 KiB
Python
196 lines
6.1 KiB
Python
from typing import Any, Dict, Optional
|
|
|
|
from astrbot.api import logger
|
|
|
|
from .base import DATA_PROCESSING_ERRORS, BaseDomainService
|
|
|
|
|
|
class ContentService(BaseDomainService):
|
|
async def helps(self) -> Dict[str, Any]:
|
|
"""帮助"""
|
|
return await self.template_result("helps.html", {})
|
|
|
|
async def bagua(self, type: str) -> Dict[str, Any]:
|
|
"""八卦"""
|
|
return_data = self.new_result()
|
|
|
|
# 1. 构造请求参数
|
|
params = {"class": type, "limit": "5"}
|
|
|
|
# 2. 调用基础请求
|
|
data: Optional[list[Dict[str, Any]]] = await self.request(
|
|
"jx3_bagua", params=params
|
|
)
|
|
|
|
# 3. 处理返回数据
|
|
try:
|
|
if not data:
|
|
result_msg = f"未找到相关 {type} 记录。\n"
|
|
result_msg += (
|
|
"可选范围:818 616 鬼网三 鬼网3 树洞 记录 "
|
|
"教程 街拍 故事 避雷 吐槽 提问"
|
|
)
|
|
else:
|
|
result_msg = f"类型:【{type}】\n\n"
|
|
|
|
for item in data:
|
|
result_msg += f"{item['title']}\n"
|
|
result_msg += f"分区:{item['zone']} 服务器:{item['server']}\n"
|
|
result_msg += f"所属吧:{item['name']}\n"
|
|
result_msg += f"链接:https://tieba.baidu.com/p/{item['url']}\n"
|
|
result_msg += f"日期:{item['date']}\n\n"
|
|
return_data["data"] = result_msg
|
|
except DATA_PROCESSING_ERRORS:
|
|
logger.exception("处理返回数据失败")
|
|
return_data["msg"] = "处理返回数据失败"
|
|
return return_data
|
|
|
|
return_data["code"] = 200
|
|
|
|
return return_data
|
|
|
|
async def hong1(self, name: str) -> Dict[str, Any]:
|
|
"""宏 心法"""
|
|
return_data = self.new_result()
|
|
|
|
# 数据库查询数据
|
|
result = await self._database.select_one(
|
|
"kungfu",
|
|
"name=? OR name1=? OR name2=? OR name3=? OR name4=? OR name5=?",
|
|
(name, name, name, name, name, name),
|
|
)
|
|
|
|
if result is None:
|
|
return_data["msg"] = "未找到该心法"
|
|
return return_data
|
|
|
|
kungfu = result.get("name", None)
|
|
if kungfu is None:
|
|
return_data["msg"] = "未找到该心法"
|
|
return return_data
|
|
|
|
logger.debug(f"查询到数据:{kungfu}")
|
|
|
|
# 1. 构造请求参数
|
|
params = {"subtype": kungfu}
|
|
|
|
# 2. 调用基础请求
|
|
data: Optional[Dict[str, Any]] = await self.request(
|
|
"jx3box_hong", params=params
|
|
)
|
|
logger.debug(data)
|
|
if not data:
|
|
return_data["msg"] = "未找到该心法一键宏"
|
|
return return_data
|
|
|
|
# 提取ID
|
|
pid_list = [0]
|
|
msg = "按照热度排列\n"
|
|
n = 1
|
|
try:
|
|
for m in data.get("list", []):
|
|
msg += f"{n}、{m['author']}\t{m['post_title']}\n"
|
|
pid_list.append(m["ID"])
|
|
n += 1
|
|
|
|
return_data["msg"] = msg
|
|
return_data["data"]["list"] = pid_list
|
|
return_data["data"]["num"] = n
|
|
|
|
except DATA_PROCESSING_ERRORS:
|
|
logger.exception("处理返回数据失败")
|
|
return_data["msg"] = "处理返回数据失败"
|
|
return return_data
|
|
|
|
return_data["code"] = 200
|
|
|
|
return return_data
|
|
|
|
async def hong2(self, pid: str) -> Dict[str, Any]:
|
|
"""宏 心法"""
|
|
return_data = self.new_result()
|
|
|
|
# 发起请求
|
|
data = await self.request(
|
|
"jx3box_hong_detail",
|
|
out_key="data",
|
|
path_params={"pid": pid},
|
|
)
|
|
# 验证数据
|
|
if not data:
|
|
return_data["msg"] = "获取宏数据异常"
|
|
return return_data
|
|
|
|
# 4. 处理数据
|
|
try:
|
|
return_data["temp"] = data["post_content"]
|
|
msg = ""
|
|
for m in data["post_meta"]["data"]:
|
|
msg += f"【宏名称】\n{m['name']}\n"
|
|
msg += f"【使用说明】\n{m['desc']}\n"
|
|
msg += f"【宏脚本】\n{m['macro']}\n\n"
|
|
|
|
return_data["data"] = msg
|
|
|
|
except DATA_PROCESSING_ERRORS:
|
|
logger.exception("处理返回数据失败")
|
|
return_data["msg"] = "处理返回数据失败"
|
|
return return_data
|
|
|
|
return_data["code"] = 200
|
|
|
|
return return_data
|
|
|
|
async def peizhuang(self, name: str, tags: str) -> Dict[str, Any]:
|
|
"""配装"""
|
|
return_data = self.new_result()
|
|
|
|
# 数据库查询数据
|
|
result = await self._database.select_one(
|
|
"kungfu",
|
|
"name=? OR name1=? OR name2=? OR name3=? OR name4=? OR name5=?",
|
|
(name, name, name, name, name, name),
|
|
)
|
|
logger.debug(result)
|
|
if result is None:
|
|
return_data["msg"] = "未找到该心法"
|
|
return return_data
|
|
|
|
mount = result.get("pzid", None)
|
|
if not mount:
|
|
return_data["msg"] = "未找到该心法"
|
|
return return_data
|
|
|
|
logger.debug(f"查询到数据:{mount}")
|
|
|
|
# 1. 构造请求参数
|
|
params = {"mount": mount, "tags": tags}
|
|
|
|
# 2. 调用基础请求
|
|
data: Optional[Dict[str, Any]] = await self.request(
|
|
"jx3box_peizhuang", params=params
|
|
)
|
|
logger.debug(data)
|
|
# 验证数据
|
|
if not data:
|
|
return_data["msg"] = "配装数据获取异常"
|
|
return return_data
|
|
|
|
# 3. 处理返回数据
|
|
try:
|
|
result_msg = f"{name}--配装\n"
|
|
for item in data["list"]:
|
|
result_msg += f"【{item['zlp']}】--{item['title']}\n"
|
|
result_msg += f"链接:https://www.jx3box.com/pz/view/{item['id']}\n\n"
|
|
|
|
return_data["data"] = result_msg
|
|
|
|
except DATA_PROCESSING_ERRORS as e:
|
|
logger.exception("处理返回数据失败:", e)
|
|
return_data["msg"] = "处理返回数据失败"
|
|
return return_data
|
|
|
|
return_data["code"] = 200
|
|
|
|
return return_data
|