mirror of
https://github.com/Shu-Ying/main_plugin_farm.git
synced 2026-11-02 18:50:08 +08:00
🎨 使用Python包管理和模块访问
🎨 重构数据库结构, 使用集中式服务定位器与数据库交互 🎨 更改部分代码逻辑, 减小内存消耗
This commit is contained in:
+23
-25
@@ -4,15 +4,14 @@ from typing import Any
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
from ...utils.config import DATA_PATH, g_sResourcePath, g_sTranslation
|
||||
from ...utils.json import g_pJsonManager
|
||||
from ...utils.tool import g_pToolManager
|
||||
from ...utils import config, getJsonManager, getToolManager
|
||||
from ..dbService import g_pDBService
|
||||
|
||||
|
||||
class CSignInManager:
|
||||
async def signInByUid(self, uid: str) -> str:
|
||||
toDay = g_pToolManager.dateTime().date().today()
|
||||
@classmethod
|
||||
async def signInByUid(cls, uid: str) -> str:
|
||||
toDay = getToolManager().dateTime().date().today()
|
||||
message = ""
|
||||
status = await g_pDBService.userSign.sign(uid, toDay.strftime("%Y-%m-%d"))
|
||||
|
||||
@@ -26,11 +25,11 @@ class CSignInManager:
|
||||
uid, toDay.strftime("%Y-%m-%d")
|
||||
)
|
||||
|
||||
message += g_sTranslation["signIn"]["success"].format(
|
||||
message += config.g_sTranslation["signIn"]["success"].format(
|
||||
day=signDay, exp=exp, num=point
|
||||
)
|
||||
|
||||
jSign = await g_pJsonManager.getSign()
|
||||
jSign = await getJsonManager().getSign()
|
||||
reward = jSign["continuou"].get(f"{signDay}", None)
|
||||
|
||||
signType = Config.get_config("zhenxun_plugin_farm", "签到图片样式")
|
||||
@@ -41,30 +40,31 @@ class CSignInManager:
|
||||
|
||||
plant = reward.get("plant", {})
|
||||
|
||||
message += g_sTranslation["signIn"]["grandTotal"].format(
|
||||
message += config.g_sTranslation["signIn"]["grandTotal"].format(
|
||||
exp=extraExp, num=extraPoint
|
||||
)
|
||||
|
||||
vipPoint = reward.get("vipPoint", 0)
|
||||
|
||||
if vipPoint > 0:
|
||||
message += g_sTranslation["signIn"]["grandTotal1"].format(
|
||||
message += config.g_sTranslation["signIn"]["grandTotal1"].format(
|
||||
num=vipPoint
|
||||
)
|
||||
|
||||
if plant:
|
||||
for key, value in plant.items():
|
||||
message += g_sTranslation["signIn"]["grandTotal2"].format(
|
||||
name=key, num=value
|
||||
)
|
||||
message += config.g_sTranslation["signIn"][
|
||||
"grandTotal2"
|
||||
].format(name=key, num=value)
|
||||
else:
|
||||
message = g_sTranslation["signIn"]["error1"]
|
||||
message = config.g_sTranslation["signIn"]["error1"]
|
||||
pass
|
||||
|
||||
return message
|
||||
|
||||
@classmethod
|
||||
def generateSignData(
|
||||
self,
|
||||
cls,
|
||||
todayRewards: list[dict[str, Any]],
|
||||
cumulativeRewards: list[dict[str, Any]],
|
||||
currentProgress: int,
|
||||
@@ -104,8 +104,9 @@ class CSignInManager:
|
||||
"consecutiveDays": consecutiveDays,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
async def createSignImage(
|
||||
self,
|
||||
cls,
|
||||
todayRewards: list[dict[str, Any]],
|
||||
cumulativeRewards: list[dict[str, Any]],
|
||||
currentProgress: int,
|
||||
@@ -122,12 +123,12 @@ class CSignInManager:
|
||||
consecutiveDays (int, optional): 连续签到天数
|
||||
"""
|
||||
try:
|
||||
templatePath = g_sResourcePath / "html/sign_in.html"
|
||||
outputPath = g_sResourcePath / "temp_html/sign_in.html"
|
||||
savePath = DATA_PATH / "farm_res/html/sign_in.png"
|
||||
templatePath = config.g_sResourcePath / "html/sign_in.html"
|
||||
outputPath = config.g_sResourcePath / "temp_html/sign_in.html"
|
||||
savePath = config.DATA_PATH / "farm_res/html/sign_in.png"
|
||||
|
||||
# 1. 生成渲染数据
|
||||
context = self.generateSignData(
|
||||
context = cls.generateSignData(
|
||||
todayRewards=todayRewards,
|
||||
cumulativeRewards=cumulativeRewards,
|
||||
currentProgress=currentProgress,
|
||||
@@ -136,19 +137,16 @@ class CSignInManager:
|
||||
)
|
||||
|
||||
# 2. 渲染HTML文件
|
||||
g_pToolManager.renderHtmlToFile(templatePath, context, outputPath)
|
||||
getToolManager().renderHtmlToFile(templatePath, context, outputPath)
|
||||
|
||||
# 3. 生成图片字节数据
|
||||
# imageBytes = await g_pToolManager.screenshotHtmlToBytes(outputPath)
|
||||
# imageBytes = await getToolManager().screenshotHtmlToBytes(outputPath)
|
||||
|
||||
# 4. 保存图片文件
|
||||
await g_pToolManager.screenshotSave(
|
||||
await getToolManager().screenshotSave(
|
||||
str(outputPath), str(savePath), 600, 800
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"❌ 生成签到图片时出错: {e}")
|
||||
raise
|
||||
|
||||
|
||||
g_pSignInManager = CSignInManager()
|
||||
|
||||
Reference in New Issue
Block a user