parent
c0416a517e
commit
59af134904
|
|
@ -12,6 +12,7 @@ class CommandType(Enum):
|
||||||
GROUP_KICK = "set_group_kick" # 踢出群聊
|
GROUP_KICK = "set_group_kick" # 踢出群聊
|
||||||
SEND_POKE = "send_poke" # 戳一戳
|
SEND_POKE = "send_poke" # 戳一戳
|
||||||
DELETE_MSG = "delete_msg" # 撤回消息
|
DELETE_MSG = "delete_msg" # 撤回消息
|
||||||
|
AI_VOICE_SEND = "send_group_ai_record" # 发送群AI语音
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.value
|
return self.value
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,8 @@ class SendHandler:
|
||||||
command, args_dict = self.handle_poke_command(seg_data.get("args"), group_info)
|
command, args_dict = self.handle_poke_command(seg_data.get("args"), group_info)
|
||||||
case CommandType.DELETE_MSG.name:
|
case CommandType.DELETE_MSG.name:
|
||||||
command, args_dict = self.delete_msg_command(seg_data.get("args"))
|
command, args_dict = self.delete_msg_command(seg_data.get("args"))
|
||||||
|
case CommandType.AI_VOICE_SEND.name:
|
||||||
|
command, args_dict = self.handle_ai_voice_send_command(seg_data.get("args"), group_info)
|
||||||
case _:
|
case _:
|
||||||
logger.error(f"未知命令: {command_name}")
|
logger.error(f"未知命令: {command_name}")
|
||||||
return
|
return
|
||||||
|
|
@ -378,6 +380,32 @@ class SendHandler:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def handle_ai_voice_send_command(self, args: Dict[str, Any], group_info: GroupInfo) -> Tuple[str, Dict[str, Any]]:
|
||||||
|
"""
|
||||||
|
处理AI语音发送命令的逻辑。
|
||||||
|
并返回 NapCat 兼容的 (action, params) 元组。
|
||||||
|
"""
|
||||||
|
if not group_info or not group_info.group_id:
|
||||||
|
raise ValueError("AI语音发送命令必须在群聊上下文中使用")
|
||||||
|
if not args:
|
||||||
|
raise ValueError("AI语音发送命令缺少参数")
|
||||||
|
|
||||||
|
group_id: int = int(group_info.group_id)
|
||||||
|
character_id = args.get("character")
|
||||||
|
text_content = args.get("text")
|
||||||
|
|
||||||
|
if not character_id or not text_content:
|
||||||
|
raise ValueError(f"AI语音发送命令参数不完整: character='{character_id}', text='{text_content}'")
|
||||||
|
|
||||||
|
return (
|
||||||
|
CommandType.AI_VOICE_SEND.value,
|
||||||
|
{
|
||||||
|
"group_id": group_id,
|
||||||
|
"text": text_content,
|
||||||
|
"character": character_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
async def send_message_to_napcat(self, action: str, params: dict) -> dict:
|
async def send_message_to_napcat(self, action: str, params: dict) -> dict:
|
||||||
request_uuid = str(uuid.uuid4())
|
request_uuid = str(uuid.uuid4())
|
||||||
payload = json.dumps({"action": action, "params": params, "echo": request_uuid})
|
payload = json.dumps({"action": action, "params": params, "echo": request_uuid})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue