from __future__ import annotations from typing import Optional from Plugins.WPSAPI import GuideEntry from .WPSRedPacketBase import WPSRedPacketBase class WPSRandomRedPacket(WPSRedPacketBase): """手气红包入口插件""" def get_guide_subtitle(self) -> str: return "发起手气红包,随机拆分积分给指定人数" def collect_command_entries(self): return ( GuideEntry( title="红包", identifier="红包 <金额> <人数>", description="按照随机手气拆分积分,缺省金额/人数使用配置项。", metadata={"别名": "手气红包"}, ), ) def wake_up(self) -> None: self.register_plugin("红包") 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() tokens = [token.strip() for token in payload.split() if token.strip()] service = self.red_packet_service() try: amount, slots, _ = self.parse_amount_and_slots(tokens) self.validate_amount_and_slots(amount, slots) self.ensure_sufficient_points(user_id, amount) packet = service.create_random_packet(chat_id, user_id, amount, slots) hint = f"- 提示:使用 `抢红包 {packet.packet_id}` 抢夺份额。" return await self.send_markdown_message( self.format_packet_message(packet, hint), chat_id, user_id, ) except ValueError as exc: return await self.send_markdown_message(self.format_error(str(exc)), chat_id, user_id) __all__ = ["WPSRandomRedPacket"]