This commit is contained in:
qsc
2025-12-07 15:58:35 +08:00
parent 2572c1d239
commit 11123568e1
6 changed files with 275 additions and 61 deletions
+1 -34
View File
@@ -1,36 +1,3 @@
{
"jx3_kfjk_en": {
"description": "开服监控功能",
"type": "bool",
"default": true,
"hint": "是否启用剑网三开服监控功能。"
},
"jx3_kfjk_time": {
"description": "开服监控循环时间",
"type": "int",
"default": 5,
"hint": "请求服务器状态的循环时间,单位秒。"
},
"jx3_kfjk_server": {
"description": "开服监控服务器",
"type": "string",
"default": "梦江南",
"hint": "请求服务器状态的名称,要官方名称。"
},
"jx3_kfjk_list": {
"description": "开服监控推送列表",
"type": "list",
"hint": "可以填写多个会话唯一ID。",
"items": {
"type": "string",
"description": "会话唯一ID"
},
"default": ["default:GroupMessage:768280021","default:GroupMessage:690665795"]
},
"jx3_kfjk_test": {
"description": "开服监控功能测试",
"type": "bool",
"default": false,
"hint": "可以手动修改服务器的状态,进行推送测试。"
}
}
+112 -2
View File
@@ -174,13 +174,13 @@ class WZRYFunction:
sql = "SELECT * FROM wzrybl"
sqlid = await self.__db.fetch_all(sql)
except Exception as e:
logger.error(f"处理数据时出错: {e}")
logger.error(f"SQL执行错误: {e}")
return_data["msg"] = "处理数据库信息时出错"
return return_data
# 加载模板
try:
return_data["temp"] = load_template("temp_test.html")
return_data["temp"] = load_template("bilei.html")
except FileNotFoundError as e:
logger.error(f"加载模板失败: {e}")
return_data["msg"] = "系统错误:模板文件不存在"
@@ -188,3 +188,113 @@ class WZRYFunction:
return_data["data"]["lists"] = sqlid
return_data["code"] = 200
return return_data
async def bilei_add(self,name:str, text:str, user:str):
"""
仇人 添加
"""
return_data = {
"code": 0,
"msg": "功能函数未执行",
"data": {}
}
# 获取系统时间
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 插入数据
try:
sql = "INSERT INTO wzrybl (name, text, time, user) VALUES (%s, %s, %s, %s)"
await self.__db.execute(sql, (name, text, now, user))
except Exception as e:
logger.error(f"SQL执行错误: {e}")
return_data["msg"] = "处理数据库信息时出错"
return return_data
return_data["msg"] = "添加成功\n"
return_data["msg"] += "仇人名称:"+name+"\n"
return_data["msg"] += "仇人备注:"+text+"\n"
return_data["msg"] += "添加时间:"+now+"\n"
return_data["msg"] += "记录人:"+user+"\n"
return_data["code"] = 200
return return_data
async def bilei_select(self,name:str):
"""
仇人 查找
"""
return_data = {
"code": 0,
"msg": "功能函数未执行",
"data": {}
}
# 查询数据
try:
sql = "SELECT * FROM wzrybl WHERE name LIKE %s"
sqlid = await self.__db.fetch_all(sql, ("%"+name+"%",))
except Exception as e:
logger.error(f"SQL执行错误: {e}")
return_data["msg"] = "处理数据库信息时出错"
return return_data
# 加载模板
try:
return_data["temp"] = load_template("bilei.html")
except FileNotFoundError as e:
logger.error(f"加载模板失败: {e}")
return_data["msg"] = "系统错误:模板文件不存在"
return return_data
return_data["data"]["lists"] = sqlid
return_data["code"] = 200
return return_data
async def bilei_update(self, id:int, name:str, text:str, user:str):
"""
仇人 修改 ID 名称 备注
"""
return_data = {
"code": 0,
"msg": "功能函数未执行",
"data": {}
}
# 获取系统时间
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 查询数据
try:
sql = "UPDATE wzrybl SET name = %s, text = %s, time = %s, user = %s WHERE id = %s"
rowcount = await self.__db.execute(sql, (name, text, now, user, id))
if rowcount > 0:
return_data["msg"] = "修改成功\n"
return_data["msg"] += "仇人名称:"+name+"\n"
return_data["msg"] += "仇人备注:"+text+"\n"
return_data["msg"] += "修改时间:"+now+"\n"
return_data["msg"] += "记录人:"+user+"\n"
return_data["code"] = 200
else:
return_data["msg"] = "修改失败,未找到对应记录"
except Exception as e:
logger.error(f"SQL执行错误: {e}")
return_data["msg"] = "处理数据库信息时出错"
return return_data
return return_data
async def bilei_delete(self, id:int):
"""
仇人 删除 ID
"""
return_data = {
"code": 0,
"msg": "功能函数未执行",
"data": {}
}
# 查询数据
try:
sql = "DELETE FROM wzrybl WHERE id = %s"
rowcount = await self.__db.execute(sql, (id,))
if rowcount > 0:
return_data["msg"] = "删除成功\n"
return_data["code"] = 200
else:
return_data["msg"] = "删除失败,未找到对应记录"
except Exception as e:
logger.error(f"SQL执行错误: {e}")
return_data["msg"] = "处理数据库信息时出错"
return return_data
return return_data
+58 -15
View File
@@ -15,7 +15,7 @@ from .core.WZRYFunction import WZRYFunction
@register("astrbot_plugin_gok",
"飞翔大野猪",
"通过接口调用剑网三API接口获取游戏数据",
"通过接口接口获取王者荣耀游戏数据",
"1.0.0",
"https://github.com/qsc20001102/astrbot_plugin_gok"
)
@@ -32,8 +32,7 @@ class GokApiPlugin(Star):
with open(self.api_file_path, 'r', encoding='utf-8') as f:
self.api_config = json.load(f)
# 初始化数据
self.inidata()
logger.info("jx3api插件初始化完成")
logger.info("王者荣耀插件初始化完成")
async def initialize(self):
@@ -54,12 +53,7 @@ class GokApiPlugin(Star):
# 周期函数调用
logger.info("jx3api插件创建实例完成")
def inidata(self):
"""数据初始化"""
self.test_server = False
logger.info("数据初始化完成")
logger.info("王者荣耀插件创建实例完成")
@filter.command_group("王者")
@@ -148,8 +142,12 @@ class GokApiPlugin(Star):
logger.error(f"功能函数执行错误: {e}")
yield event.plain_result("猪脑过载,请稍后再试")
@filter.command("仇人列表")
async def wz_bilei(self, event: AstrMessageEvent,):
@filter.command_group("仇人")
def bilei(self):
pass
@bilei.command("列表")
async def bilei_list(self, event: AstrMessageEvent,):
"""仇人 列表"""
try:
data = await self.wzry.bilei_all()
@@ -159,8 +157,54 @@ class GokApiPlugin(Star):
else:
yield event.plain_result(data["msg"])
return
#logger.info(f"输出结果{event.get_sender_name()}\n{out}")
#yield event.plain_result(f"{out}")
except Exception as e:
logger.error(f"功能函数执行错误: {e}")
yield event.plain_result("猪脑过载,请稍后再试")
@bilei.command("添加")
async def bilei_add(self, event: AstrMessageEvent,name: str, text: str):
"""仇人 添加 名称 备注"""
try:
data = await self.wzry.bilei_add(name, text, event.get_sender_name())
yield event.plain_result(data["msg"])
except Exception as e:
logger.error(f"功能函数执行错误: {e}")
yield event.plain_result("猪脑过载,请稍后再试")
@bilei.command("查找")
async def bilei_select(self, event: AstrMessageEvent,name: str):
"""仇人 查找 名称(模糊查找)"""
try:
data = await self.wzry.bilei_select(name)
if data["code"] == 200:
url = await self.html_render(data["temp"], data["data"], options={})
yield event.image_result(url)
else:
yield event.plain_result(data["msg"])
return
except Exception as e:
logger.error(f"功能函数执行错误: {e}")
yield event.plain_result("猪脑过载,请稍后再试")
@bilei.command("修改")
async def bilei_update(self, event: AstrMessageEvent,id:int, name: str, text: str):
"""仇人 修改 ID 名称 备注"""
try:
data = await self.wzry.bilei_update(id, name, text, event.get_sender_name())
yield event.plain_result(data["msg"])
except Exception as e:
logger.error(f"功能函数执行错误: {e}")
yield event.plain_result("猪脑过载,请稍后再试")
@bilei.command("删除")
async def bilei_delete(self, event: AstrMessageEvent,id:int):
"""仇人 删除 ID """
try:
data = await self.wzry.bilei_delete(id)
yield event.plain_result(data["msg"])
except Exception as e:
logger.error(f"功能函数执行错误: {e}")
yield event.plain_result("猪脑过载,请稍后再试")
@@ -170,5 +214,4 @@ class GokApiPlugin(Star):
"""可选择实现异步的插件销毁方法,当插件被卸载/停用时会调用。"""
await self.db.close_pool()
# 后台进程销毁
self.kf_task.cancel()
logger.info("jx3api插件已卸载/停用")
logger.info("王者荣耀插件已卸载/停用")
+1
View File
@@ -1,4 +1,5 @@
name: astrbot_plugin_gok # 这是你的插件的唯一识别名。
display_name: 王者荣耀数据查询工具 # 插件的显示名称
desc: 王者荣耀的战绩、资料等内容的查询 # 插件简短描述
version: v1.0.0 # 插件版本号。格式:v1.1.1 或者 v1.1
author: 飞翔大野猪 # 作者
+97
View File
@@ -0,0 +1,97 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>王者荣耀 — 仇人列表</title>
<style>
body {
font-family: 'Microsoft YaHei', Arial, sans-serif;
background: #f1f2f6;
margin: 0;
padding: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
text-align: center; /* ★ 让容器内标题更自然居中 */
}
h1 {
font-size: 32px;
margin-bottom: 25px;
color: #222;
font-weight: 800;
text-align: center; /* ★ 强制居中 */
}
table {
width: 100%;
border-collapse: collapse;
background: white;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 4px 16px rgba(0,0,0,0.08);
margin-top: 10px;
text-align: left; /* 不影响表格内容 */
}
thead {
background: #d93939;
color: white;
font-size: 18px;
}
th, td {
padding: 14px 12px;
border-bottom: 1px solid #eee;
font-size: 16px;
}
tbody tr:hover {
background: #fff2f2;
}
.text-col {
max-width: 360px;
line-height: 1.5em;
word-break: break-word;
font-weight: 600;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h1>仇人列表</h1>
<table>
<thead>
<tr>
<th>ID</th>
<th>名称</th>
<th>描述</th>
<th>时间</th>
<th>记录者</th>
</tr>
</thead>
<tbody>
{% for m in lists %}
<tr>
<td>{{ m.id }}</td>
<td>{{ m.name }}</td>
<td class="text-col">{{ m.text }}</td>
<td>{{ m.time }}</td>
<td>{{ m.user }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
+5 -9
View File
@@ -65,18 +65,16 @@
<body>
<div class="container">
<h1>王者荣耀 — 仇人列表</h1>
<h1>仇人列表</h1>
<table>
<thead>
<tr>
<th>ID</th>
<th>名称</th>
<th>英雄</th>
<th>分路</th>
<th>记录者</th>
<th>时间</th>
<th>描述</th>
<th>时间</th>
<th>记录者</th>
</tr>
</thead>
@@ -85,11 +83,9 @@
<tr>
<td>{{ m.id }}</td>
<td>{{ m.name }}</td>
<td>{{ m.hero }}</td>
<td>{{ m.fenglu }}</td>
<td>{{ m.user }}</td>
<td>{{ m.time }}</td>
<td class="text-col">{{ m.text }}</td>
<td>{{ m.time }}</td>
<td>{{ m.user }}</td>
</tr>
{% endfor %}
</tbody>