1.新增一些配方2.新增红包系统3.WPSConfigSystem中新增用户名替换空白字符机制

This commit is contained in:
2025-11-17 21:19:14 +08:00
parent 0342d83916
commit 803fb9d49f
9 changed files with 855 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ from PWF.Convention.Runtime.Config import *
from PWF.Convention.Runtime.Architecture import Architecture
from PWF.Convention.Runtime.GlobalConfig import ProjectConfig
from datetime import datetime
import re
from PWF.CoreModules.plugin_interface import DatabaseModel, get_db
@@ -71,6 +72,7 @@ class WPSConfigAPI(WPSAPI):
@override
def wake_up(self) -> None:
self._sanitize_usernames()
logger.Log("Info", f"{ConsoleFrontColor.GREEN}WPSConfigAPI 插件已加载{ConsoleFrontColor.RESET}")
self.register_plugin("config")
self.register_plugin("cfg")
@@ -203,6 +205,36 @@ class WPSConfigAPI(WPSAPI):
value = record.get("username")
return str(value) if value else f"user_{user_id}"
def _sanitize_usernames(self) -> None:
cursor = get_db().conn.cursor()
try:
cursor.execute("SELECT user_id, username FROM user_info")
rows = cursor.fetchall()
except Exception as exc:
logger.Log("Error", f"查询 user_info 失败: {exc}")
return
updated = 0
for row in rows:
user_id = row["user_id"]
username = row["username"] or ""
if not username or not re.search(r"\s", username):
continue
sanitized = re.sub(r"\s+", "_", username.strip())
if sanitized == username:
continue
try:
cursor.execute(
"UPDATE user_info SET username = ? WHERE user_id = ?",
(sanitized, user_id),
)
updated += 1
except Exception as exc:
logger.Log("Error", f"更新 user_id={user_id} 的用户名失败: {exc}")
if updated:
get_db().conn.commit()
logger.Log("Info", f"已替换 {updated} 条含空白字符的用户名")
def find_user_id_by_username(self, username: str) -> Optional[int]:
text = (username or "").strip()
if not text: