72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
"""Remove (clear) plot 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 WPSGardenRemove(WPSGardenBase):
|
|
def get_guide_subtitle(self) -> str:
|
|
return "清理地块以重新种植"
|
|
|
|
def collect_command_entries(self) -> Sequence[GuideEntry]:
|
|
return (
|
|
GuideEntry(
|
|
title="铲除",
|
|
identifier="铲除 <地块序号>",
|
|
description="清空指定地块,移除作物与成熟计时。",
|
|
metadata={"别名": "remove"},
|
|
icon="🧹",
|
|
details=[
|
|
{
|
|
"type": "list",
|
|
"items": [
|
|
"常用于处理枯萎或不再需要的作物。",
|
|
"操作不可逆,被铲除的作物不会返还种子。",
|
|
],
|
|
}
|
|
],
|
|
),
|
|
)
|
|
|
|
def collect_guide_entries(self) -> Sequence[GuideEntry]:
|
|
return (
|
|
{
|
|
"title": "使用场景",
|
|
"description": "用于清理枯萎或不再需要的作物,释放地块。",
|
|
},
|
|
)
|
|
|
|
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"]
|