新增日常类型插件类

This commit is contained in:
2025-11-06 20:41:25 +08:00
parent 599705d79e
commit 2be8563f41
4 changed files with 48 additions and 23 deletions

View File

@@ -1,3 +0,0 @@
{
"entries": []
}

2
PWF

Submodule PWF updated: 4ad222cbc7...14ce7e6e3f

View File

@@ -209,7 +209,7 @@ class WPSAPI(BasicWPSInterface):
@override @override
def wake_up(self) -> None: def wake_up(self) -> None:
config.Log("Info", "WPSAPI核心插件已加载") config.Log("Info", f"{ConsoleFrontColor.GREEN}WPSAPI核心插件已加载{ConsoleFrontColor.RESET}")
self.register_plugin("say") self.register_plugin("say")
self.register_plugin("") self.register_plugin("")

View File

@@ -3,16 +3,13 @@ from __future__ import annotations
import asyncio import asyncio
import time import time
from PWF.Convention.Runtime import Config
from PWF.Convention.Runtime.Config import *
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from PWF.Convention.Runtime.Config import *
from PWF.Convention.Runtime.EasySave import EasySave, EasySaveSetting from PWF.Convention.Runtime.Architecture import Architecture
from PWF.Convention.Runtime.File import ToolFile from PWF.Convention.Runtime.File import ToolFile
from PWF.Convention.Runtime.GlobalConfig import ProjectConfig from PWF.Convention.Runtime.GlobalConfig import ProjectConfig
from .WPSAPI import BasicWPSInterface, LimitStringLength, get_internal_debug, WPSAPI from .WPSAPI import WPSAPI
config = ProjectConfig() config = ProjectConfig()
@@ -28,7 +25,7 @@ class UserConfigStore(BaseModel):
entries: List[UserConfigEntry] = Field(default_factory=list) entries: List[UserConfigEntry] = Field(default_factory=list)
class WPSConfigPlugin(BasicWPSInterface): class WPSConfigAPI(WPSAPI):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
self._lock = asyncio.Lock() self._lock = asyncio.Lock()
@@ -41,20 +38,20 @@ class WPSConfigPlugin(BasicWPSInterface):
def dependencies(self) -> List[Type]: def dependencies(self) -> List[Type]:
return [WPSAPI] return [WPSAPI]
def _build_setting(self) -> ToolFile: #EasySaveSetting: @override
data_file: ToolFile = config.GetFile("user_configs.easysave", False) def is_enable_plugin(self) -> bool:
return True
def _build_setting(self) -> ToolFile:
data_file: ToolFile = config.GetFile("user_configs.json", False)
data_file.TryCreateParentPath() data_file.TryCreateParentPath()
if data_file.Exists() == False: if data_file.Exists() == False:
data_file.SaveAsJson(self._store) data_file.SaveAsJson(self._store)
return data_file return data_file
@override
def is_enable_plugin(self) -> bool:
return True
@override @override
def wake_up(self) -> None: def wake_up(self) -> None:
config.Log("Info", "WPSConfigPlugin 插件已加载") config.Log("Info", f"{ConsoleFrontColor.GREEN}WPSConfigAPI 插件已加载{ConsoleFrontColor.RESET}")
self.register_plugin("config") self.register_plugin("config")
self.register_plugin("cfg") self.register_plugin("cfg")
@@ -222,9 +219,8 @@ class WPSConfigPlugin(BasicWPSInterface):
def get_user_name(self, chat_id: int, user_id: int) -> Optional[str]: def get_user_name(self, chat_id: int, user_id: int) -> Optional[str]:
entry = self._entries.get((chat_id, user_id)) entry = self._entries.get((chat_id, user_id))
if not entry: if not entry:
return None return f"user_{user_id}"
value = entry.data.get("user.name") return str(entry.data.get("user.name", f"user_{user_id}"))
return str(value) if value is not None else None
def get_user_url(self, chat_id: int, user_id: int) -> Optional[str]: def get_user_url(self, chat_id: int, user_id: int) -> Optional[str]:
entry = self._entries.get((chat_id, user_id)) entry = self._entries.get((chat_id, user_id))
@@ -255,7 +251,39 @@ class WPSConfigPlugin(BasicWPSInterface):
) )
class WPSDailyAPI(WPSAPI):
@override
def dependencies(self) -> List[Type]:
return [WPSAPI]
@override
def is_enable_plugin(self) -> bool:
return True
@override
def wake_up(self) -> None:
config.Log("Info", f"{ConsoleFrontColor.GREEN}WPSDailyAPI 插件已加载{ConsoleFrontColor.RESET}")
self.register_plugin("daily")
def _get_today_checkin_status(self, user_id: int) -> bool:
# TODO: 获取今日签到状态
return False
async def do_callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
# 不匹配时默认返回当前的分数信息
return f'''# 积分信息
- 当前分数: {Architecture.Get(WPSConfigAPI).get_user_points(chat_id, user_id)}
- 今日签到状态: {"已签到" if self._get_today_checkin_status(user_id) else "未签到"}
'''
@override
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
message = self.parse_message_after_at(message)
message = await self.do_callback(message, chat_id, user_id)
return await self.send_markdown_message(message, chat_id, user_id)
config.SaveProperties() config.SaveProperties()
__all__ = ["WPSConfigPlugin"] __all__ = ["WPSConfigAPI"]