from __future__ import annotations from collections.abc import Awaitable, Callable from typing import Any, TYPE_CHECKING if TYPE_CHECKING: from yuxi.channels.message_actions import ActionStatus, MessageAction WECHAT_MESSAGE_ACTIONS: dict[str, dict[str, Any]] = { "send": {"status": "implemented", "impl": "adapter.send()"}, "broadcast": {"status": "unsupported", "reason": "WeChat API doesn't support broadcast"}, "reply": {"status": "implemented", "impl": "adapter.py (bridge reply_to_mode + wecom/mp reply quoting)"}, "sendWithEffect": {"status": "unsupported", "reason": "WeChat doesn't support message effects"}, "sendAttachment": {"status": "implemented", "impl": "adapter.send_media()"}, "sticker": {"status": "unsupported", "reason": "WeChat doesn't support stickers"}, "sticker-search": {"status": "unsupported", "reason": "WeChat doesn't support stickers"}, "sticker-upload": {"status": "unsupported", "reason": "WeChat doesn't support stickers"}, "edit": {"status": "unsupported", "reason": "WeChat API doesn't support message editing"}, "unsend": {"status": "unsupported", "reason": "WeChat API doesn't support unsend"}, "delete": {"status": "unsupported", "reason": "WeChat API doesn't support delete"}, "read": {"status": "implemented", "impl": "message_read.py"}, "pin": {"status": "unsupported", "reason": "WeChat doesn't support pin"}, "unpin": {"status": "unsupported", "reason": "WeChat doesn't support pin"}, "list-pins": {"status": "unsupported", "reason": "WeChat doesn't support pin"}, "permissions": {"status": "unsupported", "reason": "WeChat doesn't support permission API"}, "timeout": {"status": "unsupported", "reason": "WeChat doesn't support timeout/kick"}, "kick": {"status": "unsupported", "reason": "WeChat doesn't support kick API"}, "ban": {"status": "unsupported", "reason": "WeChat doesn't support ban API"}, "react": {"status": "unsupported", "reason": "WeChat doesn't support Reaction"}, "reactions": {"status": "unsupported", "reason": "WeChat doesn't support Reaction"}, "poll": {"status": "unsupported", "reason": "WeChat doesn't support Poll"}, "poll-vote": {"status": "unsupported", "reason": "WeChat doesn't support Poll"}, "emoji-list": {"status": "unsupported", "reason": "WeChat doesn't support Emoji API"}, "emoji-upload": {"status": "unsupported", "reason": "WeChat doesn't support Emoji API"}, "voice-status": {"status": "unsupported", "reason": "WeChat doesn't support voice status"}, "renameGroup": {"status": "implemented", "impl": "group_admin.py"}, "setGroupIcon": {"status": "unsupported", "reason": "WeCom API doesn't support group icon change"}, "addParticipant": {"status": "implemented", "impl": "group_admin.py"}, "removeParticipant": {"status": "implemented", "impl": "group_admin.py"}, "leaveGroup": {"status": "unsupported", "reason": "WeCom doesn't support leave group via API"}, "channel-info": {"status": "unsupported", "reason": "WeChat doesn't support channel concept"}, "channel-list": {"status": "unsupported", "reason": "WeChat doesn't support channel concept"}, "channel-create": {"status": "unsupported", "reason": "WeChat doesn't support channel concept"}, "channel-edit": {"status": "unsupported", "reason": "WeChat doesn't support channel concept"}, "channel-delete": {"status": "unsupported", "reason": "WeChat doesn't support channel concept"}, "channel-move": {"status": "unsupported", "reason": "WeChat doesn't support channel concept"}, "category-create": {"status": "unsupported", "reason": "WeChat doesn't support category concept"}, "category-edit": {"status": "unsupported", "reason": "WeChat doesn't support category concept"}, "category-delete": {"status": "unsupported", "reason": "WeChat doesn't support category concept"}, "topic-create": {"status": "unsupported", "reason": "WeChat doesn't support topic concept"}, "topic-edit": {"status": "unsupported", "reason": "WeChat doesn't support topic concept"}, "thread-create": {"status": "unsupported", "reason": "WeChat doesn't support thread concept"}, "thread-list": {"status": "unsupported", "reason": "WeChat doesn't support thread concept"}, "thread-reply": {"status": "unsupported", "reason": "WeChat doesn't support thread concept"}, "member-info": {"status": "unsupported", "reason": "WeChat doesn't support member info API"}, "role-info": {"status": "unsupported", "reason": "WeChat doesn't support role concept"}, "role-add": {"status": "unsupported", "reason": "WeChat doesn't support role concept"}, "role-remove": {"status": "unsupported", "reason": "WeChat doesn't support role concept"}, "event-list": {"status": "unsupported", "reason": "WeChat doesn't support event API"}, "event-create": {"status": "unsupported", "reason": "WeChat doesn't support event API"}, "download-file": {"status": "implemented", "impl": "adapter.download_media()"}, "upload-file": {"status": "implemented", "impl": "adapter.send_media()"}, "search": {"status": "unsupported", "reason": "WeChat doesn't support message search API"}, "set-profile": {"status": "unsupported", "reason": "WeChat doesn't support profile API"}, "set-presence": {"status": "unsupported", "reason": "WeChat doesn't support presence API"}, } class WeChatMessageActionAdapter: @staticmethod def is_supported(action_name: str) -> bool: info = WECHAT_MESSAGE_ACTIONS.get(action_name, {}) return info.get("status") == "implemented" @staticmethod def get_handler(action_name: str) -> Callable[..., Awaitable[Any]] | None: return None @staticmethod def list_supported_actions() -> list[str]: return [k for k, v in WECHAT_MESSAGE_ACTIONS.items() if v.get("status") == "implemented"] @staticmethod def list_all_actions() -> dict[str, dict[str, Any]]: return dict(WECHAT_MESSAGE_ACTIONS) def _status_to_action_status(status: str) -> ActionStatus: from yuxi.channels.message_actions import ActionStatus status_map = { "implemented": ActionStatus.SUPPORTED, "planned": ActionStatus.PARTIAL, "unsupported": ActionStatus.UNSUPPORTED, } return status_map.get(status, ActionStatus.UNSUPPORTED) def _action_name_to_enum(name: str) -> MessageAction | None: from yuxi.channels.message_actions import MessageAction mapping: dict[str, str] = { "send": "send", "broadcast": "broadcast", "reply": "reply", "sendWithEffect": "send_with_effect", "sendAttachment": "send_attachment", "sticker": "sticker", "sticker-search": "sticker_search", "sticker-upload": "sticker_upload", "edit": "edit", "unsend": "unsend", "delete": "delete", "read": "read", "pin": "pin", "unpin": "unpin", "list-pins": "list_pins", "permissions": "permissions", "timeout": "mute", "kick": "kick", "ban": "ban", "react": "react", "reactions": "list_reactions", "poll": "create_poll", "poll-vote": "close_poll", "emoji-list": "emoji_list", "emoji-upload": "emoji_upload", "voice-status": "voice_status", "renameGroup": "rename_group", "setGroupIcon": "set_group_icon", "addParticipant": "add_participant", "removeParticipant": "remove_participant", "leaveGroup": "leave_group", "channel-info": "channel_info", "channel-list": "channel_list", "channel-create": "channel_create", "channel-edit": "channel_edit", "channel-delete": "channel_delete", "channel-move": "channel_move", "category-create": "category_create", "category-edit": "category_edit", "category-delete": "category_delete", "topic-create": "topic_create", "topic-edit": "topic_edit", "thread-create": "thread_create", "thread-list": "thread_list", "thread-reply": "thread_reply", "member-info": "member_info", "role-info": "role_info", "role-add": "role_add", "role-remove": "role_remove", "event-list": "event_list", "event-create": "event_create", "download-file": "download_file", "upload-file": "upload_file", "search": "search", "set-profile": "set_profile", "set-presence": "set_presence", } try: return MessageAction(mapping[name]) except (KeyError, ValueError): return None def register_wechat_actions() -> None: from yuxi.channels.message_actions import ActionDeclaration, ActionRegistry declarations: dict = {} for action_name, info in WECHAT_MESSAGE_ACTIONS.items(): action_enum = _action_name_to_enum(action_name) if action_enum is None: continue declarations[action_enum] = ActionDeclaration( action=action_enum, status=_status_to_action_status(info.get("status", "unsupported")), reason=info.get("reason", ""), impl=info.get("impl", ""), ) ActionRegistry.register_channel_actions("wechat", declarations)