diff --git a/plugins/xiuxian/main.py b/plugins/xiuxian/main.py index bfd9c4f..fa74ce6 100644 --- a/plugins/xiuxian/main.py +++ b/plugins/xiuxian/main.py @@ -1740,7 +1740,45 @@ class XiuxianPlugin(MessagePluginInterface): return False, "劫掠失败" - async def _cmd_give_stone(self, bot: WechatAPIClient, sender: str, roomid: str, content: str) -> Tuple[bool, str]: + async def _cmd_give_stone(self, bot: WechatAPIClient, sender: str, roomid: str, content: str, message: Dict[str, Any]) -> Tuple[bool, str]: + msg = message.get("full_wx_msg") + xml = getattr(msg, "msg_source", None) if msg else None + target_wxid = None + if roomid and xml: + try: + import xml.etree.ElementTree as ET + import re + root = ET.fromstring(xml) + at_el = root.find('.//atuserlist') + text = (at_el.text if at_el is not None else '').strip() + text = text.strip(',') + text = re.sub(r'[\\s\\u3000]+', '', text) + at_set = set(text.split(',')) + at_set.discard('') + if len(at_set) != 1: + await self._send_text_with_status(bot, sender, roomid, "请@一个明确的目标进行赠与", 90) + return False, "目标无效" + target_wxid = next(iter(at_set)) + tokens = [t for t in content.strip().split() if not t.startswith('@')] + if len(tokens) < 1: + return False, "道友施法有误,指令格式不对" + try: + qty = int(tokens[0]) + except Exception: + return False, "道友施法有误,指令格式不对" + except Exception: + pass + if not target_wxid: + parts = content.strip().split() + if len(parts) < 2: + await self._send_text_with_status(bot, sender, roomid, "格式:赠与 目标 数量", 90) + return False, "命令格式错误" + target_wxid = parts[0].lstrip("@") + try: + qty = int(parts[1]) + except Exception: + await self._send_text_with_status(bot, sender, roomid, "格式:赠与 目标 数量", 90) + return False, "命令格式错误" parts = content.strip().split() if len(parts) < 2: await self._send_text_with_status(bot, sender, roomid, "格式:赠与 目标 数量", 90)