完成签到功能与对应的提示功能
This commit is contained in:
1
.gitmodules
vendored
1
.gitmodules
vendored
@@ -1,3 +1,4 @@
|
||||
[submodule "PWF"]
|
||||
path = PWF
|
||||
url = http://www.liubai.site:3000/ninemine/PWF.git
|
||||
branch = main
|
||||
|
||||
@@ -50,4 +50,10 @@ Yolo模式: Off
|
||||
- 更改: 放弃ES, 重新转向数据库持久化
|
||||
- 原因: 统一接口并实时读写
|
||||
- 阻碍因素: 无
|
||||
- 状态: 未确认
|
||||
- 状态: 成功
|
||||
|
||||
[2025-11-07_22:11:00]
|
||||
- 已修改: Plugins/WPSDailyAPI
|
||||
- 更改: 完成签到功能与对应的提示功能
|
||||
- 阻碍因素: 无
|
||||
- 状态: 成功
|
||||
2
PWF
2
PWF
Submodule PWF updated: 477fbf1876...c49f55808e
@@ -3,13 +3,14 @@ from __future__ import annotations
|
||||
from PWF.Convention.Runtime.Config import *
|
||||
from PWF.Convention.Runtime.Architecture import Architecture
|
||||
from PWF.Convention.Runtime.GlobalConfig import ProjectConfig
|
||||
from datetime import datetime
|
||||
|
||||
from PWF.CoreModules.plugin_interface import DatabaseModel, get_db
|
||||
|
||||
from .WPSAPI import WPSAPI
|
||||
|
||||
config = ProjectConfig()
|
||||
|
||||
CHECKIN_POINTS = config.FindItem("checkin_points", 100)
|
||||
|
||||
class WPSConfigAPI(WPSAPI):
|
||||
@override
|
||||
@@ -203,16 +204,42 @@ class WPSDailyAPI(WPSAPI):
|
||||
config.Log("Info", f"{ConsoleFrontColor.GREEN}WPSDailyAPI 插件已加载{ConsoleFrontColor.RESET}")
|
||||
self.register_plugin("daily")
|
||||
|
||||
@override
|
||||
def register_db_model(self) -> DatabaseModel:
|
||||
return DatabaseModel(
|
||||
table_name="daily_checkin",
|
||||
column_defs={
|
||||
"user_id": "INTEGER PRIMARY KEY",
|
||||
"checkin_date": "TEXT",
|
||||
}
|
||||
)
|
||||
|
||||
def _get_today_checkin_status(self, user_id: int) -> bool:
|
||||
# TODO: 获取今日签到状态
|
||||
return False
|
||||
cursor = get_db().conn.cursor()
|
||||
cursor.execute("SELECT checkin_date FROM daily_checkin WHERE user_id = ?", (user_id,))
|
||||
row = cursor.fetchone()
|
||||
return row is not None and row[0] == datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
def _set_today_checkin_status(self, user_id: int) -> None:
|
||||
cursor = get_db().conn.cursor()
|
||||
cursor.execute("INSERT INTO daily_checkin (user_id, checkin_date) VALUES (?, ?)", (user_id, datetime.now().strftime("%Y-%m-%d")))
|
||||
get_db().conn.commit()
|
||||
|
||||
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 "未签到"}
|
||||
'''
|
||||
tokens = [token.strip() for token in message.strip().split() if token.strip()]
|
||||
if not tokens:
|
||||
return self._help_message(chat_id, user_id)
|
||||
action = tokens[0].lower()
|
||||
if action == "checkin":
|
||||
return await self._handle_checkin(chat_id, user_id)
|
||||
return self._help_message()
|
||||
|
||||
async def _handle_checkin(self, chat_id: int, user_id: int) -> str:
|
||||
wps_config_api: "WPSConfigAPI" = Architecture.Get(WPSConfigAPI)
|
||||
if self._get_today_checkin_status(user_id):
|
||||
return "今日已签到"
|
||||
self._set_today_checkin_status(user_id)
|
||||
return f"签到成功, 当前分数: {await wps_config_api.adjust_user_points(chat_id, user_id, CHECKIN_POINTS, "每日签到")}"
|
||||
|
||||
@override
|
||||
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
|
||||
@@ -220,10 +247,13 @@ class WPSDailyAPI(WPSAPI):
|
||||
message = await self.do_callback(message, chat_id, user_id)
|
||||
return await self.send_markdown_message(message, chat_id, user_id)
|
||||
|
||||
def _help_message(self) -> str:
|
||||
return '''# 📅 Daily 命令帮助
|
||||
def _help_message(self, chat_id: int, user_id: int) -> str:
|
||||
wps_config_api: "WPSConfigAPI" = Architecture.Get(WPSConfigAPI)
|
||||
return f'''# 📅 Daily 命令帮助
|
||||
- daily checkin: 签到
|
||||
- daily get: 获取今日签到状态
|
||||
---
|
||||
- 当前分数: {wps_config_api.get_user_points(chat_id, user_id)}
|
||||
- 今日签到状态: {"已签到" if self._get_today_checkin_status(user_id) else "未签到"}
|
||||
'''
|
||||
|
||||
config.SaveProperties()
|
||||
|
||||
Reference in New Issue
Block a user