78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
"""Remove trap plugin for garden system."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional, Sequence
|
|
|
|
from Plugins.WPSAPI import GuideEntry
|
|
|
|
from .garden_plugin_base import WPSGardenBase
|
|
|
|
|
|
class WPSGardenRemoveTrap(WPSGardenBase):
|
|
def get_guide_subtitle(self) -> str:
|
|
return "移除地块上的防护陷阱"
|
|
|
|
def collect_command_entries(self) -> Sequence[GuideEntry]:
|
|
return (
|
|
GuideEntry(
|
|
title="移除陷阱",
|
|
identifier="移除陷阱 <地块序号>",
|
|
description="移除地块上的陷阱。",
|
|
metadata={"别名": "remove_trap"},
|
|
icon="🗑️",
|
|
details=[
|
|
{
|
|
"type": "steps",
|
|
"items": [
|
|
"输入地块序号。",
|
|
"系统检查地块是否存在且是否有陷阱。",
|
|
"成功移除陷阱。",
|
|
],
|
|
},
|
|
],
|
|
),
|
|
)
|
|
|
|
def collect_guide_entries(self) -> Sequence[GuideEntry]:
|
|
return (
|
|
{
|
|
"title": "指令格式",
|
|
"description": "`移除陷阱 <地块序号>`。",
|
|
},
|
|
)
|
|
|
|
def wake_up(self) -> None:
|
|
super().wake_up()
|
|
self.register_plugin("移除陷阱")
|
|
self.register_plugin("remove_trap")
|
|
|
|
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
|
|
payload = self.parse_message_after_at(message).strip()
|
|
if not payload:
|
|
return await self.send_markdown_message(
|
|
"❌ 指令格式:`移除陷阱 <地块序号>`",
|
|
chat_id, user_id
|
|
)
|
|
|
|
tokens = [token.strip() for token in payload.split() if token.strip()]
|
|
if not tokens or not tokens[0].isdigit():
|
|
return await self.send_markdown_message(
|
|
"❌ 指令格式:`移除陷阱 <地块序号>`",
|
|
chat_id, user_id
|
|
)
|
|
|
|
plot_index = int(tokens[0])
|
|
try:
|
|
self.service().remove_trap(user_id=user_id, plot_index=plot_index)
|
|
return await self.send_markdown_message(
|
|
f"✅ 已移除地块 {plot_index} 上的陷阱",
|
|
chat_id, user_id
|
|
)
|
|
except ValueError as exc:
|
|
return await self.send_markdown_message(f"❌ {exc}", chat_id, user_id)
|
|
|
|
|
|
__all__ = ["WPSGardenRemoveTrap"]
|
|
|