"""Remove (clear) plot plugin for garden system.""" from __future__ import annotations from typing import Optional from .garden_plugin_base import WPSGardenBase class WPSGardenRemove(WPSGardenBase): def wake_up(self) -> None: super().wake_up() self.register_plugin("remove") self.register_plugin("铲除") 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]) if plot_index <= 0: return await self.send_markdown_message("❌ 地块序号必须为正整数", chat_id, user_id) success = self.service().clear_plot(user_id=user_id, plot_index=plot_index) if not success: return await self.send_markdown_message("❌ 指定地块不存在或已为空", chat_id, user_id) message_body = ( "# 🧹 铲除完成\n" f"- 已清空地块 {plot_index}\n" "- 可以重新种植新的作物" ) return await self.send_markdown_message(message_body, chat_id, user_id) __all__ = ["WPSGardenRemove"]