新增菜园系统
This commit is contained in:
@@ -167,7 +167,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
|
||||
backpack = Architecture.Get(WPSBackpackSystem)
|
||||
try:
|
||||
item_def = backpack._get_definition(item_id) # type: ignore[attr-defined]
|
||||
item_def = backpack._get_definition(item_id)
|
||||
except Exception as exc:
|
||||
raise ValueError(f"Item {item_id} not registered in backpack system") from exc
|
||||
|
||||
@@ -292,7 +292,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
now = datetime.now(timezone.utc).isoformat()
|
||||
backpack = Architecture.Get(WPSBackpackSystem)
|
||||
for mode in selection:
|
||||
definition = backpack._get_definition(mode.item_id) # type: ignore[attr-defined]
|
||||
definition = backpack._get_definition(mode.item_id)
|
||||
remaining = mode.limit_amount if mode.limit_amount >= 0 else -1
|
||||
cursor.execute(
|
||||
f"""
|
||||
@@ -338,7 +338,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
now = datetime.now(timezone.utc).isoformat()
|
||||
backpack = Architecture.Get(WPSBackpackSystem)
|
||||
for mode in permanent_modes:
|
||||
definition = backpack._get_definition(mode.item_id) # type: ignore[attr-defined]
|
||||
definition = backpack._get_definition(mode.item_id)
|
||||
cursor.execute(
|
||||
f"""
|
||||
INSERT INTO {self.SYSTEM_TABLE} (
|
||||
@@ -621,7 +621,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
for row in rows:
|
||||
item_id = row["item_id"]
|
||||
try:
|
||||
definition = backpack._get_definition(item_id) # type: ignore[attr-defined]
|
||||
definition = backpack._get_definition(item_id)
|
||||
item_name = definition.name
|
||||
except Exception:
|
||||
item_name = item_id
|
||||
@@ -706,8 +706,8 @@ class WPSStoreSystem(WPSAPI):
|
||||
user_id: int,
|
||||
) -> str:
|
||||
total_price = entry.price * quantity
|
||||
config_api = Architecture.Get(WPSConfigAPI)
|
||||
user_points = Architecture.Get(WPSConfigAPI).get_user_points(chat_id, user_id)
|
||||
config_api: WPSConfigAPI = Architecture.Get(WPSConfigAPI)
|
||||
user_points = config_api.get_user_points(user_id)
|
||||
if user_points < total_price:
|
||||
return f"❌ 积分不足,需要 {total_price} 分,当前仅有 {user_points} 分"
|
||||
|
||||
@@ -756,7 +756,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
matches.append(listing)
|
||||
continue
|
||||
try:
|
||||
definition = backpack._get_definition(listing.item_id) # type: ignore[attr-defined]
|
||||
definition = backpack._get_definition(listing.item_id)
|
||||
except Exception:
|
||||
continue
|
||||
if definition.name.lower() == identifier_lower:
|
||||
@@ -779,8 +779,8 @@ class WPSStoreSystem(WPSAPI):
|
||||
return "❌ 无法购买自己上架的商品"
|
||||
|
||||
total_price = listing.price * quantity
|
||||
config_api = Architecture.Get(WPSConfigAPI)
|
||||
buyer_points = config_api.get_user_points(chat_id, user_id)
|
||||
config_api: WPSConfigAPI = Architecture.Get(WPSConfigAPI)
|
||||
buyer_points = config_api.get_user_points(user_id)
|
||||
if buyer_points < total_price:
|
||||
return f"❌ 积分不足,需要 {total_price} 分,当前仅有 {buyer_points} 分"
|
||||
|
||||
@@ -818,7 +818,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
backpack = Architecture.Get(WPSBackpackSystem)
|
||||
backpack.add_item(user_id, listing.item_id, quantity)
|
||||
|
||||
definition = backpack._get_definition(listing.item_id) # type: ignore[attr-defined]
|
||||
definition = backpack._get_definition(listing.item_id)
|
||||
return (
|
||||
f"✅ 成功购买玩家商品 {definition.name} × {quantity},花费 {total_price} 分\n"
|
||||
f"当前剩余积分:{buyer_new_points}"
|
||||
@@ -857,7 +857,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
item_id = row["item_id"]
|
||||
backpack: WPSBackpackSystem = Architecture.Get(WPSBackpackSystem)
|
||||
try:
|
||||
definition = backpack._get_definition(item_id) # type: ignore[attr-defined]
|
||||
definition = backpack._get_definition(item_id)
|
||||
item_name = definition.name
|
||||
except Exception:
|
||||
item_name = item_id
|
||||
@@ -902,7 +902,7 @@ class WPSStoreSystem(WPSAPI):
|
||||
row = cursor.fetchone()
|
||||
item_id = row["item_id"] if row else identifier
|
||||
try:
|
||||
definition = backpack._get_definition(item_id) # type: ignore[attr-defined]
|
||||
definition = backpack._get_definition(item_id)
|
||||
return definition.item_id, definition
|
||||
except Exception:
|
||||
return None, None
|
||||
@@ -1002,7 +1002,7 @@ class WPSStoreBuyCommand(WPSAPI):
|
||||
except ValueError:
|
||||
return await self._send_error("❌ 购买数量必须是整数", chat_id, user_id)
|
||||
|
||||
store_api = Architecture.Get(WPSStoreSystem)
|
||||
store_api: WPSStoreSystem = Architecture.Get(WPSStoreSystem)
|
||||
response = await store_api.purchase_item(
|
||||
chat_id=chat_id,
|
||||
user_id=user_id,
|
||||
|
||||
Reference in New Issue
Block a user