fixed # 新增本地部署脚本,一键生成对应平台的压缩包内容

This commit is contained in:
2026-10-22 18:33:42 +08:00
parent 37c933db0c
commit d238005561
41 changed files with 1158 additions and 545 deletions
+12
View File
@@ -7,3 +7,15 @@
生成时修正为插件私有相对导入,本目录本身不是完整安装包。
使用 scripts/build_zhenxun.py 生成ZIP,详见 docs/11-zhenxun-preview.md。
本轮没有拉取、推送或操作真实机器人。
## 图片质量
真寻网页插件配置新增“农场图片质量”,整数1~95,默认75。
它统一控制我的农场、地块编号、农场详述、种子商店、我的种子及
我的作物图片的编码质量,修改后下一次图片请求生效。值越高通常
越清晰、文件越大;不会改变默认图片尺寸,PNG无损格式不受影响。
无效配置明确提示错误,不会自动截断或转换为合法值。
只有“我的农场 高清”接受高清,宽1536,质量取配置值与85的较大值。
其他命令不接受高清。仓库继续支持“我的种子 2 文字”和
“我的作物 2 文字”等分页文字查询。
+7 -1
View File
@@ -1,7 +1,7 @@
"""真寻农场独立预览插件入口。"""
from nonebot.plugin import PluginMetadata
from zhenxun.configs.utils import Command, PluginExtraData
from zhenxun.configs.utils import Command, PluginExtraData, RegisterConfig
from ._version import __version__
from .runtime import COMMANDS, HELP
@@ -14,6 +14,12 @@ __plugin_meta__ = PluginMetadata(
extra=PluginExtraData(
author="Shu-Ying", version=__version__, menu_type="群内小游戏",
commands=[Command(command=name) for name in COMMANDS],
configs=[RegisterConfig(
key="农场图片质量", value=75, default_value=75, type=int,
help="全部农场图片的编码质量,整数1~95,默认75;"
"数值越高通常越清晰、文件越大。仅我的农场支持高清,"
"高清质量不低于85。PNG为无损格式,不受此值影响。",
)],
).to_dict(),
)
+10
View File
@@ -18,6 +18,15 @@ from .runtime import COMMANDS, Runtime
from .data_paths import data_directory
from .config_migration import migrate_config
def image_quality():
from zhenxun.configs.config import Config
return Config.get(__package__.split('.')[-1]).get(
'农场图片质量', 75, build_model=False,
)
logger = logging.getLogger(__name__)
driver = get_driver()
data_dir = data_directory(
@@ -29,6 +38,7 @@ runtime = Runtime(
getattr(driver.config, "farm_preview_deployment", "zhenxun-preview"),
str(getattr(driver.config, "farm_preview_image_format", "AUTO")).upper(),
font_dir=FONT_PATH,
image_quality_provider=image_quality,
)
async def start_runtime():
from zhenxun.configs.config import Config
+31 -7
View File
@@ -34,15 +34,17 @@ COMMANDS = {
}
HELP = (
"开通农场 [名称]|我的农场 [高清]|农场详述 [页码]\n"
"地块编号 [高清]|查看当前土地编号及开垦位置\n"
"地块编号|查看当前土地编号及开垦位置\n"
"偷菜 @目标|每日最多5次成功偷取\n"
"我的种子/我的作物 [页码] [高清/文字],默认标准压缩图。\n"
"我的种子/我的作物 [页码] [文字],默认图片。\n"
"全部图片使用农场图片质量配置;仅我的农场支持高清。\n"
"种子商店 [页码]|购买种子 作物 数量|播种 作物 [数量]\n"
"收获|铲除|农场除虫|我的种子 [页码]|我的作物 [页码]\n"
"作物加锁 作物|作物解锁 作物|出售作物 [作物] [数量]\n"
"作物可填写名称或 #编号;同名作物请使用商店或仓库中的编号。\n"
"每成功播种1块地获得2经验;收获经验按作物结算。\n"
"每铲除1块枯萎地块获得2经验;每清除1只虫获得1经验。\n"
"新播种及下一季每半个基础生长周期生虫一次,间隔至少2小时。\n"
"每只虫使生长速度降低5%;成熟时每只虫使本季减产5%。\n"
"成熟后除虫不能恢复本季减产;生长期间可发送:农场除虫。\n"
"我的农场按北京时间自动切换春夏秋冬背景;高清使用相同季节。\n"
@@ -88,7 +90,11 @@ def operation_id(bot_id, platform, user_id, message_id, action):
class Runtime:
def __init__(self, data_dir, font_path=None, deployment="zhenxun-preview",
image_format="AUTO", *, font_dir=None,
font_setting="FARM_PREVIEW_FONT"):
font_setting="FARM_PREVIEW_FONT", image_quality=75,
image_quality_provider=None):
RenderOptions(quality=image_quality)
self.image_quality = image_quality
self.image_quality_provider = image_quality_provider
self.data_dir = Path(data_dir).resolve()
self.font_path = font_path
self.font_setting = font_setting
@@ -198,6 +204,21 @@ class Runtime:
)
if action == "help":
return HELP
image_actions = ('farm', 'plot_ids', 'details', 'shop',
'seeds', 'crops')
if action in image_actions and action != 'farm' and '高清' in args:
return '仅我的农场支持高清,请移除高清参数后重试。'
quality = self.image_quality
text_mode = (action in ('seeds', 'crops') and args
and args[-1] == '文字')
if action in image_actions and self.rendering and not text_mode:
try:
if self.image_quality_provider is not None:
quality = self.image_quality_provider()
RenderOptions(quality=quality)
except (TypeError, ValueError):
logger.warning('farm image quality config invalid')
return '农场图片质量配置无效,请设置为1~95的整数。'
if action == "shop":
page = int(args[0]) if args else 1
if len(args) > 1:
@@ -216,6 +237,7 @@ class Runtime:
return await self.rendering.seed_shop(
chunk, account, page, pages,
image_format=self.image_format,
quality=quality,
)
return f'种子商店 第{page}/{pages}页\n' + '\n'.join(
f'{p.name}(#{p.plant_id}):'
@@ -243,10 +265,11 @@ class Runtime:
return await self.rendering.farm_details(
who, snapshot, now, page, season_for(now),
image_format=self.image_format, avatar=avatar,
quality=quality,
)
if action in ('crops', 'seeds'):
title = '我的作物' if action == 'crops' else '我的种子'
mode = args.pop() if args and args[-1] in ('高清', '文字') else ''
mode = args.pop() if args and args[-1] == '文字' else ''
if len(args) > 1:
raise ValueError()
try:
@@ -263,7 +286,7 @@ class Runtime:
return warehouse_text(rows, snapshot, action, page, pages)
return await self.rendering.warehouse(
rows, snapshot, action, page, pages, self.image_format,
mode == '高清',
quality=quality,
)
if action == "inventory":
if args:
@@ -280,9 +303,10 @@ class Runtime:
theme = season_for(now)
logger.info("farm preview seasonal theme=%s", theme)
options = (
RenderOptions.high(format=self.image_format, theme=theme)
RenderOptions(width=1536, quality=max(quality, 85),
format=self.image_format, theme=theme)
if args else RenderOptions(format=self.image_format,
theme=theme)
theme=theme, quality=quality)
)
if action == "plot_ids":
options = replace(options, show_plot_ids=True)