新增debug模式的give指令

This commit is contained in:
2025-11-11 22:32:41 +08:00
parent f8d02fbf86
commit fe4ce37c16

View File

@@ -7,6 +7,7 @@ from typing import Dict, List, Optional, override
from PWF.Convention.Runtime.Architecture import Architecture from PWF.Convention.Runtime.Architecture import Architecture
from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig
from PWF.CoreModules.database import get_db from PWF.CoreModules.database import get_db
from PWF.CoreModules.flags import get_internal_debug
from .WPSAPI import WPSAPI from .WPSAPI import WPSAPI
@@ -419,6 +420,36 @@ class WPSItemDescription(WPSAPI):
lines.append(f"- 提示:{note}") lines.append(f"- 提示:{note}")
return "\n".join(lines) return "\n".join(lines)
if get_internal_debug():
class WPSDebugGiveItem(WPSAPI):
@override
def dependencies(self) -> List[type]:
return [WPSBackpackSystem]
@override
def is_enable_plugin(self) -> bool:
return True
@override
def wake_up(self) -> None:
self.register_plugin("give")
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
payload = self.parse_message_after_at(message).strip()
if payload == "":
return await self.send_markdown_message("❌ 指令格式:`give <物品ID> [数量]`", chat_id, user_id)
tokens = [token.strip() for token in payload.split() if token.strip()]
if not tokens or not tokens[0]:
return await self.send_markdown_message("❌ 指令格式:`give <物品ID> [数量]`", chat_id, user_id)
item_id = tokens[0]
quantity = int(tokens[1]) if len(tokens) > 1 else 1
if quantity <= 0:
return await self.send_markdown_message("❌ 数量必须大于0", chat_id, user_id)
backpack: WPSBackpackSystem = Architecture.Get(WPSBackpackSystem)
backpack.add_item(user_id, item_id, quantity)
return await self.send_markdown_message(f"✅ 成功给予 {quantity}{item_id} 给用户 {user_id}", chat_id, user_id)
__all__ = [ __all__ = [
"WPSBackpackSystem", "WPSBackpackSystem",
"BackpackItemTier", "BackpackItemTier",