From 5a4f87eacb085aab9d3a715245c83dcf1bc379c7 Mon Sep 17 00:00:00 2001 From: qsc20001102 Date: Thu, 4 Dec 2025 09:22:20 +0800 Subject: [PATCH 1/5] 11 --- core/jx3_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/jx3_service.py b/core/jx3_service.py index b45743b..aa04abe 100644 --- a/core/jx3_service.py +++ b/core/jx3_service.py @@ -4,7 +4,7 @@ from typing import Dict, Any, Optional, List, Union from astrbot.api import logger from .request import APIClient -from .AsyncMySQL import AsyncMySQL +from .async_mysql import AsyncMySQL from .function_basic import load_template,flatten_field,extract_fields,gold_to_string class JX3Service: From ecd17c7721dd89a202cb44fb1cf71711ce3749fb Mon Sep 17 00:00:00 2001 From: qsc20001102 Date: Thu, 4 Dec 2025 09:35:40 +0800 Subject: [PATCH 2/5] 11 --- core/async_mysql.py | 2 ++ core/request.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/async_mysql.py b/core/async_mysql.py index 75a89f1..022ee56 100644 --- a/core/async_mysql.py +++ b/core/async_mysql.py @@ -1,5 +1,6 @@ import aiomysql +from astrbot.api import logger class AsyncMySQL: def __init__(self, db_config: dict): @@ -71,6 +72,7 @@ class AsyncMySQL: keys = ", ".join(f"`{k}`" for k in data.keys()) placeholders = ", ".join(["%s"] * len(data)) sql = f"INSERT INTO `{table}` ({keys}) VALUES ({placeholders})" + logger.info(f"Executing SQL: {sql}") return await self.execute(sql, tuple(data.values())) async def update_record(self, table: str, data: dict, where: dict): diff --git a/core/request.py b/core/request.py index 7b43000..8526a06 100644 --- a/core/request.py +++ b/core/request.py @@ -2,8 +2,8 @@ import json import aiohttp from typing import Optional, Dict, Any, Union, List - from aiohttp import ClientTimeout, ClientSession + from astrbot.api import logger class APIClient: From 587182c3b101d4cbc4ac2b85d783148957b7f4d0 Mon Sep 17 00:00:00 2001 From: qsc20001102 Date: Thu, 4 Dec 2025 09:58:32 +0800 Subject: [PATCH 3/5] 11 --- core/async_mysql.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/async_mysql.py b/core/async_mysql.py index 022ee56..66862ed 100644 --- a/core/async_mysql.py +++ b/core/async_mysql.py @@ -35,6 +35,7 @@ class AsyncMySQL: await cursor.execute(sql, params or ()) return await cursor.fetchall() + async def execute(self, sql: str, params=None): """执行 SQL(insert/update/delete)""" await self.init_pool() From 65613f99b6f64a39f73326ff084fd3bc711458ce Mon Sep 17 00:00:00 2001 From: qsc20001102 Date: Thu, 4 Dec 2025 13:13:15 +0800 Subject: [PATCH 4/5] 11 --- core/aiosqlite.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 core/aiosqlite.py diff --git a/core/aiosqlite.py b/core/aiosqlite.py new file mode 100644 index 0000000..11a4f5a --- /dev/null +++ b/core/aiosqlite.py @@ -0,0 +1,58 @@ +import aiosqlite + +class AsyncSQLite: + def __init__(self, db_path: str): + self.db_path = db_path + self.conn = None + + async def init(self): + if self.conn is None: + self.conn = await aiosqlite.connect(self.db_path) + self.conn.row_factory = aiosqlite.Row + + async def close(self): + if self.conn: + await self.conn.close() + self.conn = None + + async def fetch_one(self, sql: str, params=None): + await self.init() + async with self.conn.execute(sql, params or ()) as cursor: + row = await cursor.fetchone() + return dict(row) if row else None + + async def fetch_all(self, sql: str, params=None): + await self.init() + async with self.conn.execute(sql, params or ()) as cursor: + rows = await cursor.fetchall() + return [dict(r) for r in rows] + + async def execute(self, sql: str, params=None): + await self.init() + async with self.conn.execute(sql, params or ()): + await self.conn.commit() + return True + + async def executemany(self, sql: str, params_list): + await self.init() + await self.conn.executemany(sql, params_list) + await self.conn.commit() + return True + + async def insert_record(self, table: str, data: dict): + keys = ", ".join(f"`{k}`" for k in data.keys()) + placeholders = ", ".join(['?'] * len(data)) + sql = f"INSERT INTO `{table}` ({keys}) VALUES ({placeholders})" + return await self.execute(sql, tuple(data.values())) + + async def update_record(self, table: str, data: dict, where: dict): + set_clause = ", ".join(f"`{k}`=?" for k in data.keys()) + where_clause = " AND ".join(f"`{k}`=?" for k in where.keys()) + sql = f"UPDATE `{table}` SET {set_clause} WHERE {where_clause}" + params = tuple(data.values()) + tuple(where.values()) + return await self.execute(sql, params) + + async def delete_record(self, table: str, where: dict): + where_clause = " AND ".join(f"`{k}`=?" for k in where.keys()) + sql = f"DELETE FROM `{table}` WHERE {where_clause}" + return await self.execute(sql, tuple(where.values())) From b87969ee9553165a1472691da74f6ed02b623c6d Mon Sep 17 00:00:00 2001 From: qsc20001102 Date: Thu, 4 Dec 2025 13:37:44 +0800 Subject: [PATCH 5/5] 11 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 934328c..c8cce89 100644 --- a/main.py +++ b/main.py @@ -25,7 +25,7 @@ class Jx3ApiPlugin(Star): #获取配置 self.conf = config # 本地数据存储路径 - self.local_data_dir = StarTools.get_data_dir("astrbot_plugin_jx3api") + self.local_data_dir = StarTools.get_data_dir("astrbot_plugin_jx3") # api数据文件 self.api_file_path = Path(__file__).parent / "api_config.json" # 读取文件内容