43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from dataclasses import dataclass
|
||
|
|
from typing import TYPE_CHECKING, Protocol, runtime_checkable
|
||
|
|
|
||
|
|
if TYPE_CHECKING:
|
||
|
|
from yuxi.channels.models import DeliveryResult
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class ActionContext:
|
||
|
|
action: str
|
||
|
|
channel_id: str
|
||
|
|
chat_id: str
|
||
|
|
msg_id: str
|
||
|
|
args: dict
|
||
|
|
session_key: str | None = None
|
||
|
|
run_id: str | None = None
|
||
|
|
|
||
|
|
def get(self, key: str, default=None):
|
||
|
|
return self.args.get(key, default)
|
||
|
|
|
||
|
|
|
||
|
|
@runtime_checkable
|
||
|
|
class ChannelMessageActionProtocol(Protocol):
|
||
|
|
"""消息动作协议 — 编辑、删除、表情回应等增强交互能力"""
|
||
|
|
|
||
|
|
async def edit_message(self, chat_id: str, msg_id: str, content: str) -> DeliveryResult: ...
|
||
|
|
|
||
|
|
async def delete_message(self, chat_id: str, msg_id: str) -> DeliveryResult: ...
|
||
|
|
|
||
|
|
async def send_reaction(self, chat_id: str, msg_id: str, emoji: str) -> DeliveryResult: ...
|
||
|
|
|
||
|
|
def supports_action(self, action: str) -> bool: ...
|
||
|
|
|
||
|
|
def resolve_execution_mode(self, action: str) -> str: ...
|
||
|
|
|
||
|
|
async def handle_action(self, ctx: ActionContext) -> DeliveryResult: ...
|
||
|
|
|
||
|
|
def extract_target_from_args(self, args: dict) -> dict | None: ...
|
||
|
|
|
||
|
|
def describe_message_tool(self) -> dict: ...
|