🐛 修复历史遗留BUG

 预增对服务端的请求
This commit is contained in:
Art_Sakura 2025-04-09 17:14:37 +08:00
parent d17c1b8ed7
commit 194c630d4e
9 changed files with 54 additions and 26 deletions

View File

@ -10,6 +10,7 @@ from .config import g_pJsonManager
from .database import g_pSqlManager
from .farm.farm import g_pFarmManager
from .farm.shop import g_pShopManager
from .request import g_pRequestManager
__plugin_meta__ = PluginMetadata(
name="真寻农场",
@ -20,7 +21,7 @@ __plugin_meta__ = PluginMetadata(
at 开通农场
我的农场
我的农场币
种子商店
种子商店 [页数]
购买种子 [作物/种子名称] [数量]
我的种子
播种 [作物/种子名称] [数量]
@ -71,6 +72,12 @@ async def start():
# 初始化读取Json
await g_pJsonManager.init()
# a = await g_pRequestManager.sign("1754798088")
# logger.info(a)
await g_pShopManager.getSeedShopImage(1)
# 析构函数
@driver.on_shutdown
async def shutdown():

View File

@ -50,7 +50,7 @@ diuse_farm = on_alconna(
"我的农场",
Option("--all", action=store_true),
Subcommand("my-point", help_text="我的农场币"),
Subcommand("seed-shop", help_text="种子商店"),
Subcommand("seed-shop", Args["num?", int], help_text="种子商店"),
Subcommand("buy-seed", Args["name?", str]["num?", int], help_text="购买种子"),
Subcommand("my-seed", help_text="我的种子"),
Subcommand("sowing", Args["name?", str]["num?", int], help_text="播种"),
@ -96,20 +96,20 @@ async def _(session: Uninfo):
await MessageUtils.build_message(f"你的当前农场币为: {point}").send(reply_to=True)
diuse_farm.shortcut(
"种子商店",
"种子商店(.*?)",
command="我的农场",
arguments=["seed-shop"],
prefix=True,
)
@diuse_farm.assign("seed-shop")
async def _(session: Uninfo):
async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)):
uid = str(session.user.id)
if await isRegisteredByUid(uid) == False:
return
image = await g_pShopManager.getSeedShopImage()
image = await g_pShopManager.getSeedShopImage(num.result)
await MessageUtils.build_message(image).send()
diuse_farm.shortcut(

View File

@ -1,4 +1,5 @@
{
"version": 0.01,
"zhuShi":
[
"name: 名称",
@ -18,4 +19,4 @@
"sell": true
}
}
}
}

View File

@ -1,4 +1,5 @@
{
"version": 0.01,
"soil":[1, 1, 1, 2, 3, 5, 7, 9, 11, 13,
15, 17, 19, 21, 23, 25, 27, 29, 31, 33,
36, 39, 42, 45, 48, 51, 54, 57, 60, 70
@ -7,31 +8,31 @@
{
"4":
{
"level": 3,
"level": 2,
"point": 800,
"item": []
},
"5":
{
"level": 5,
"level": 3,
"point": 1300,
"item": []
},
"6":
{
"level": 7,
"level": 5,
"point": 3200,
"item": []
},
"7":
{
"level": 9,
"level": 7,
"point": 5500,
"item": []
},
"8":
{
"level": 12,
"level": 9,
"point": 12000,
"item": []
},

View File

@ -1,4 +1,5 @@
{
"version": 0.01,
"zhuShi":
[
"level: 解锁等级",

View File

@ -1,4 +1,5 @@
{
"version": 0.01,
"size":[234, 156],
"soil":
{

View File

@ -436,13 +436,18 @@ class CSqlManager:
s = ""
else:
#获取种子信息 这里能崩我吃
plantInfo = g_pJsonManager.m_pPlant['plant'][plant] #type: ignore
plantInfo = g_pJsonManager.m_pPlant['plant'][plant]
currentTime = datetime.now()
newTime = currentTime + timedelta(hours=int(plantInfo['time']))
#种子名称种下时间预计成熟时间地状态0无 1长草 2生虫 3缺水 4枯萎是否被偷 示例QQ号-偷取数量|QQ号-偷取数量
s = f"{plant},{int(currentTime.timestamp())},{int(newTime.timestamp())},{status},"
#0: 种子名称
#1: 种下时间
#2: 预计成熟时间
#3: 地状态0无 1长草 2生虫 3缺水 4枯萎
#4: 是否被偷 示例QQ号-偷取数量|QQ号-偷取数量
#5: 土地等级 0普通 1红土地 2黑土地 3金土地 4紫晶土地 5蓝晶土地 6黑晶土地
s = f"{plant},{int(currentTime.timestamp())},{int(newTime.timestamp())},{status},,"
sql = f"UPDATE soil SET {soil} = '{s}' WHERE uid = {uid}"

View File

@ -1,3 +1,5 @@
import math
from zhenxun.services.log import logger
from zhenxun.utils._build_image import BuildImage
from zhenxun.utils.image_utils import ImageTemplate
@ -9,11 +11,9 @@ from ..database import g_pSqlManager
class CShopManager:
@classmethod
async def getSeedShopImage(cls) -> bytes:
async def getSeedShopImage(cls, num: int = 1) -> bytes:
"""获取商店页面
TODO: 缺少翻页功能
Returns:
bytes: 返回商店图片bytes
"""
@ -33,8 +33,12 @@ class CShopManager:
]
sell = ""
plants = g_pJsonManager.m_pPlant['plant'] # type: ignore
for key, plant in plants.items():
plants = list(g_pJsonManager.m_pPlant['plant'].items())
start = (num - 1) * 15
maxItems = min(len(plants) - start, 15)
items = plants[start:start + maxItems]
for key, plant in items:
icon = ""
icon_path = g_sResourcePath / f"plant/{key}/icon.png"
if icon_path.exists():
@ -60,8 +64,11 @@ class CShopManager:
]
)
count = math.ceil(len(g_pJsonManager.m_pPlant['plant']) / 15)
title = f"种子商店 页数: {num}/{count}"
result = await ImageTemplate.table_page(
"种子商店",
title,
"购买示例:@小真寻 购买种子 大白菜 5",
column_name,
data_list,
@ -88,11 +95,10 @@ class CShopManager:
plantInfo = None
try:
plantInfo = g_pJsonManager.m_pPlant['plant'][name] # type: ignore
plantInfo = g_pJsonManager.m_pPlant['plant'][name]
except Exception as e:
return "购买出错!请检查需购买的种子名称!"
level = await g_pSqlManager.getUserLevelByUid(uid)
if level[0] < int(plantInfo['level']):
@ -141,7 +147,7 @@ class CShopManager:
plant_name, count_str = item.split('|', 1)
try:
count = int(count_str)
plant_info = g_pJsonManager.m_pPlant['plant'][plant_name] # type: ignore
plant_info = g_pJsonManager.m_pPlant['plant'][plant_name]
point += plant_info['price'] * count
except Exception:
continue
@ -172,7 +178,7 @@ class CShopManager:
#计算收益
try:
plantInfo = g_pJsonManager.m_pPlant['plant'][name] # type: ignore
plantInfo = g_pJsonManager.m_pPlant['plant'][name]
totalPoint = plantInfo['price'] * totalSold
except KeyError:
return f"出售作物{name}出错:作物不存在"

View File

@ -28,8 +28,14 @@ class CRequestManager:
a = await cls.post("http://diuse.work:9099/testPost", json_data={"level":3})
result = ""
if int(a["type"]) == 1:
result = f"签到成功"
type = int(a["type"])
if type == 1:
result = f"签到成功 type = 1"
elif type == 2:
result = f"签到成功 type = 2"
else:
result = f"签到成功 type = {type}"
return result