Merge branch 'Beta' of https://github.com/Shu-Ying/zhenxun_plugin_farm into Beta
This commit is contained in:
commit
cca3dc5d4d
@ -37,7 +37,7 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
""".strip(),
|
""".strip(),
|
||||||
extra=PluginExtraData(
|
extra=PluginExtraData(
|
||||||
author="Art_Sakura",
|
author="Art_Sakura",
|
||||||
version="1.2",
|
version="1.3",
|
||||||
commands=[Command(command="我的农场")],
|
commands=[Command(command="我的农场")],
|
||||||
menu_type="群内小游戏",
|
menu_type="群内小游戏",
|
||||||
configs=[
|
configs=[
|
||||||
|
|||||||
24
command.py
24
command.py
@ -6,6 +6,7 @@ from nonebot_plugin_alconna import (Alconna, AlconnaMatch, AlconnaQuery, Args,
|
|||||||
from nonebot_plugin_uninfo import Uninfo
|
from nonebot_plugin_uninfo import Uninfo
|
||||||
from nonebot_plugin_waiter import waiter
|
from nonebot_plugin_waiter import waiter
|
||||||
|
|
||||||
|
from zhenxun.configs.config import BotConfig
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
from zhenxun.utils.message import MessageUtils
|
from zhenxun.utils.message import MessageUtils
|
||||||
|
|
||||||
@ -41,7 +42,6 @@ async def handle_register(session: Uninfo):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 获取原始用户名并安全处理
|
|
||||||
raw_name = str(session.user.name)
|
raw_name = str(session.user.name)
|
||||||
safe_name = sanitize_username(raw_name)
|
safe_name = sanitize_username(raw_name)
|
||||||
|
|
||||||
@ -120,6 +120,7 @@ diuse_farm = on_alconna(
|
|||||||
Alconna(
|
Alconna(
|
||||||
"我的农场",
|
"我的农场",
|
||||||
Option("--all", action=store_true),
|
Option("--all", action=store_true),
|
||||||
|
Subcommand("detail", help_text="农场详述"),
|
||||||
Subcommand("my-point", help_text="我的农场币"),
|
Subcommand("my-point", help_text="我的农场币"),
|
||||||
Subcommand("seed-shop", Args["num?", int], help_text="种子商店"),
|
Subcommand("seed-shop", Args["num?", int], help_text="种子商店"),
|
||||||
Subcommand("buy-seed", Args["name?", str]["num?", int], help_text="购买种子"),
|
Subcommand("buy-seed", Args["name?", str]["num?", int], help_text="购买种子"),
|
||||||
@ -148,6 +149,27 @@ async def _(session: Uninfo):
|
|||||||
image = await g_pFarmManager.drawFarmByUid(uid)
|
image = await g_pFarmManager.drawFarmByUid(uid)
|
||||||
await MessageUtils.build_message(image).send(reply_to=True)
|
await MessageUtils.build_message(image).send(reply_to=True)
|
||||||
|
|
||||||
|
diuse_farm.shortcut(
|
||||||
|
"农场详述",
|
||||||
|
command="我的农场",
|
||||||
|
arguments=["detail"],
|
||||||
|
prefix=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
@diuse_farm.assign("detail")
|
||||||
|
async def _(session: Uninfo):
|
||||||
|
uid = str(session.user.id)
|
||||||
|
|
||||||
|
if await isRegisteredByUid(uid) == False:
|
||||||
|
return
|
||||||
|
|
||||||
|
info = await g_pFarmManager.drawDetailFarmByUid(uid)
|
||||||
|
|
||||||
|
a = await MessageUtils.alc_forward_msg(info, session.self_id, BotConfig.self_nickname).send(reply_to=True)
|
||||||
|
|
||||||
|
logger.info(f"{a}")
|
||||||
|
|
||||||
|
|
||||||
diuse_farm.shortcut(
|
diuse_farm.shortcut(
|
||||||
"我的农场币",
|
"我的农场币",
|
||||||
command="我的农场",
|
command="我的农场",
|
||||||
|
|||||||
@ -18,7 +18,7 @@ class CUserSoilDB(CSqlManager):
|
|||||||
#matureTime: 成熟时间
|
#matureTime: 成熟时间
|
||||||
#soilLevel: 土地等级 0=普通地,1=红土地,2=黑土地,3=金土地
|
#soilLevel: 土地等级 0=普通地,1=红土地,2=黑土地,3=金土地
|
||||||
#wiltStatus: 枯萎状态 0=未枯萎,1=枯萎
|
#wiltStatus: 枯萎状态 0=未枯萎,1=枯萎
|
||||||
#fertilizerStatus: 施肥状态 0=未施肥,1=施肥
|
#fertilizerStatus: 施肥状态 0=未施肥,1=施肥 2=增肥
|
||||||
#bugStatus: 虫害状态 0=无虫害,1=有虫害
|
#bugStatus: 虫害状态 0=无虫害,1=有虫害
|
||||||
#weedStatus: 杂草状态 0=无杂草,1=有杂草
|
#weedStatus: 杂草状态 0=无杂草,1=有杂草
|
||||||
#waterStatus: 缺水状态 0=不缺水,1=缺水
|
#waterStatus: 缺水状态 0=不缺水,1=缺水
|
||||||
@ -349,3 +349,30 @@ class CUserSoilDB(CSqlManager):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"播种失败!", e=e)
|
logger.error(f"播种失败!", e=e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def getUserSoilStatus(cls, uid: str, soilIndex: int) -> str:
|
||||||
|
status = []
|
||||||
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex)
|
||||||
|
|
||||||
|
if not soilInfo:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
if soilInfo.get("wiltStatus", 0) == 1:
|
||||||
|
return "枯萎"
|
||||||
|
|
||||||
|
if soilInfo.get("fertilizerStatus", 0) == 1:
|
||||||
|
status.append("施肥")
|
||||||
|
elif soilInfo.get("fertilizerStatus", 0) == 2:
|
||||||
|
status.append("增肥")
|
||||||
|
|
||||||
|
if soilInfo.get("bugStatus", 0) == 1:
|
||||||
|
status.append("虫害")
|
||||||
|
|
||||||
|
if soilInfo.get("weedStatus", 0) == 1:
|
||||||
|
status.append("杂草")
|
||||||
|
|
||||||
|
if soilInfo.get("waterStatus", 0) == 1:
|
||||||
|
status.append("缺水")
|
||||||
|
|
||||||
|
return ",".join(status)
|
||||||
|
|||||||
87
farm/farm.py
87
farm/farm.py
@ -170,6 +170,93 @@ class CFarmManager:
|
|||||||
|
|
||||||
return img.pic2bytes()
|
return img.pic2bytes()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def drawDetailFarmByUid(cls, uid: str) -> list:
|
||||||
|
info = []
|
||||||
|
|
||||||
|
farm = await cls.drawFarmByUid(uid)
|
||||||
|
|
||||||
|
info.append(BuildImage.open(farm))
|
||||||
|
|
||||||
|
dataList = []
|
||||||
|
columnName = [
|
||||||
|
"-",
|
||||||
|
"土地ID",
|
||||||
|
"作物名称",
|
||||||
|
"成熟时间",
|
||||||
|
"土地状态",
|
||||||
|
"剩余产出",
|
||||||
|
]
|
||||||
|
|
||||||
|
icon = ""
|
||||||
|
soilNumber = await g_pDBService.user.getUserSoilByUid(uid)
|
||||||
|
|
||||||
|
for i in range(1, soilNumber + 1):
|
||||||
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i)
|
||||||
|
|
||||||
|
if not soilInfo:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if soilInfo["soilLevel"] == 1:
|
||||||
|
iconPath = g_sResourcePath / f"soil/TODO.png"
|
||||||
|
else:
|
||||||
|
iconPath = g_sResourcePath / f"soil/普通土地.png"
|
||||||
|
|
||||||
|
if iconPath.exists():
|
||||||
|
icon = (iconPath, 33, 33)
|
||||||
|
|
||||||
|
plantName = soilInfo.get("plantName", "-")
|
||||||
|
|
||||||
|
if plantName == "-":
|
||||||
|
matureTime = "-"
|
||||||
|
soilStatus = "-"
|
||||||
|
plantNumber = "-"
|
||||||
|
else:
|
||||||
|
matureTime = datetime.fromtimestamp(int(soilInfo.get("matureTime", 0))).strftime("%Y-%m-%d %H:%M:%S.%f")
|
||||||
|
soilStatus = await g_pDBService.userSoil.getUserSoilStatus(uid, i)
|
||||||
|
|
||||||
|
num = await g_pDBService.userSteal.getTotalStolenCount(uid, i)
|
||||||
|
planInfo = await g_pDBService.plant.getPlantByName(plantName)
|
||||||
|
|
||||||
|
if not planInfo:
|
||||||
|
plantNumber = f"None / {num}"
|
||||||
|
else:
|
||||||
|
plantNumber = f"{planInfo['harvest']} / {num}"
|
||||||
|
|
||||||
|
dataList.append(
|
||||||
|
[
|
||||||
|
icon,
|
||||||
|
i,
|
||||||
|
plantName,
|
||||||
|
matureTime,
|
||||||
|
soilStatus,
|
||||||
|
plantNumber,
|
||||||
|
])
|
||||||
|
|
||||||
|
if len(dataList) >= 15:
|
||||||
|
result = await ImageTemplate.table_page(
|
||||||
|
"土地详细信息",
|
||||||
|
"测试N\n测试2",
|
||||||
|
columnName,
|
||||||
|
dataList,
|
||||||
|
)
|
||||||
|
|
||||||
|
info.append(result)
|
||||||
|
dataList.clear()
|
||||||
|
|
||||||
|
if i >= 30:
|
||||||
|
result = await ImageTemplate.table_page(
|
||||||
|
"土地详细信息",
|
||||||
|
"测试N\n测试2",
|
||||||
|
columnName,
|
||||||
|
dataList,
|
||||||
|
)
|
||||||
|
|
||||||
|
info.append(result)
|
||||||
|
dataList.clear()
|
||||||
|
|
||||||
|
return info
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def drawSoilPlant(cls, uid: str, soilIndex: int) -> tuple[bool, BuildImage, bool]:
|
async def drawSoilPlant(cls, uid: str, soilIndex: int) -> tuple[bool, BuildImage, bool]:
|
||||||
"""绘制植物资源
|
"""绘制植物资源
|
||||||
|
|||||||
16
farm/shop.py
16
farm/shop.py
@ -21,8 +21,8 @@ class CShopManager:
|
|||||||
bytes: 返回商店图片bytes
|
bytes: 返回商店图片bytes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data_list = []
|
dataList = []
|
||||||
column_name = [
|
columnName = [
|
||||||
"-",
|
"-",
|
||||||
"种子名称",
|
"种子名称",
|
||||||
"种子单价",
|
"种子单价",
|
||||||
@ -48,16 +48,16 @@ class CShopManager:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
icon = ""
|
icon = ""
|
||||||
icon_path = g_sResourcePath / f"plant/{plant['name']}/icon.png"
|
iconPath = g_sResourcePath / f"plant/{plant['name']}/icon.png"
|
||||||
if icon_path.exists():
|
if iconPath.exists():
|
||||||
icon = (icon_path, 33, 33)
|
icon = (iconPath, 33, 33)
|
||||||
|
|
||||||
if plant['again'] == True:
|
if plant['again'] == True:
|
||||||
sell = "可以"
|
sell = "可以"
|
||||||
else:
|
else:
|
||||||
sell = "不可以"
|
sell = "不可以"
|
||||||
|
|
||||||
data_list.append(
|
dataList.append(
|
||||||
[
|
[
|
||||||
icon,
|
icon,
|
||||||
plant['name'],
|
plant['name'],
|
||||||
@ -79,8 +79,8 @@ class CShopManager:
|
|||||||
result = await ImageTemplate.table_page(
|
result = await ImageTemplate.table_page(
|
||||||
title,
|
title,
|
||||||
"购买示例:@小真寻 购买种子 大白菜 5",
|
"购买示例:@小真寻 购买种子 大白菜 5",
|
||||||
column_name,
|
columnName,
|
||||||
data_list,
|
dataList,
|
||||||
)
|
)
|
||||||
|
|
||||||
return result.pic2bytes()
|
return result.pic2bytes()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user