diff --git a/_conf_schema.json b/_conf_schema.json index 654c645..544b7b4 100644 --- a/_conf_schema.json +++ b/_conf_schema.json @@ -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": "可以手动修改服务器的状态,进行推送测试。" - } + } \ No newline at end of file diff --git a/core/WZRYFunction.py b/core/WZRYFunction.py index 1c3bbe2..143e2aa 100644 --- a/core/WZRYFunction.py +++ b/core/WZRYFunction.py @@ -174,17 +174,127 @@ 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"] = "系统错误:模板文件不存在" return return_data 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 \ No newline at end of file diff --git a/main.py b/main.py index 2dec3b6..400d2e0 100644 --- a/main.py +++ b/main.py @@ -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,9 +142,13 @@ 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() if data["code"] == 200: @@ -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插件已卸载/停用") \ No newline at end of file + logger.info("王者荣耀插件已卸载/停用") \ No newline at end of file diff --git a/metadata.yaml b/metadata.yaml index f46e081..bd7f119 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,4 +1,5 @@ name: astrbot_plugin_gok # 这是你的插件的唯一识别名。 +display_name: 王者荣耀数据查询工具 # 插件的显示名称 desc: 王者荣耀的战绩、资料等内容的查询 # 插件简短描述 version: v1.0.0 # 插件版本号。格式:v1.1.1 或者 v1.1 author: 飞翔大野猪 # 作者 diff --git a/templates/bilei.html b/templates/bilei.html new file mode 100644 index 0000000..6cbe1ed --- /dev/null +++ b/templates/bilei.html @@ -0,0 +1,97 @@ + + + + +王者荣耀 — 仇人列表 + + + + + +
+

仇人列表

+ + + + + + + + + + + + + + {% for m in lists %} + + + + + + + + {% endfor %} + +
ID名称描述时间记录者
{{ m.id }}{{ m.name }}{{ m.text }}{{ m.time }}{{ m.user }}
+ +
+ + + diff --git a/templates/temp_test.html b/templates/temp_test.html index 19c55c1..6cbe1ed 100644 --- a/templates/temp_test.html +++ b/templates/temp_test.html @@ -65,18 +65,16 @@
-

王者荣耀 — 仇人列表

+

仇人列表

- - - - + + @@ -85,11 +83,9 @@ - - - - + + {% endfor %}
ID 名称英雄分路记录者时间 描述时间记录者
{{ m.id }} {{ m.name }}{{ m.hero }}{{ m.fenglu }}{{ m.user }}{{ m.time }} {{ m.text }}{{ m.time }}{{ m.user }}